You need to be logged in to view this content. Please login or become a member.

<<  Prev   |   Index   |   Next  >>


Temporary bodies are used to create bodies without standard features or to increase the performance of tasks involving bodies.


Correction: at 10:24 the callout says “IPartDoc::CreateBodyFromFeature3” when in fact I am using IPartDoc::CreateFeatureFromBody3.

Concerning method versions: I have noticed, and SolidWorks API tech support has confirmed, that many of the newest versions of the IModeler methods contain bugs. If you find that an IModeler method is returning Nothing for no good reason, try using the older version. Two known examples of this are IModeler::CreateBodyFromBox3 and IModeler::CreateCylindricalSurface2, which is why you should use the older versions. Also, as of SolidWorks 2011 SP 5.0, IModeler::CreateExtrusionSurface may fail as well.

Concerning surface bodies: Creating surface bodies with IModeler is significantly more complicated than creating solid bodies. After you create the surface body you will need to trim it with curves created from methods like IModeler::CreateLine and IModeler::CreateArc. These curves, in turn, must be used with ICurve::CreateTrimmedCurve2 before they can be used with ISurface::CreateTrimmedSheet. Finally, an extruded body can be created from the trimmed surface body using IModeler::CreateExtrudedBody. See the API Help example “Create Temporary Extruded Body (VBA)” for a demonstration of this.

IBody2 and IModeler contain some duplicate functionality. For example, IModeler::CreateBodyFromFaces2 and IBody2::CreateBodyFromFaces are fairly similar. When you use one of the IBody2 calls, however, you need to already have a permanent body. You can create a “empty” body using IPartDoc::CreateNewBody and then run your IBody2 call on that body.

Lesson Files

Lesson 7.3 – create spike – start
Lesson 7.3 – create spike
Code snippets


  1. edgarquintana


    I’m trying to understand more the meaning of the required array on swModeler.CreateBodyFromCone(dblConeData)

    specifically on
    dblConeData(0) ‘x location
    dblConeData(1) ‘y location
    dblConeData(2) ‘z location
    dblConeData(3) ‘x direction
    dblConeData(4) ‘y direction
    dblConeData(5) ‘z direction

    It seems to be that coneFaceCenter[3] is the end coordinate of the vector and coneAxis[3]
    is the beginning coordinate of the vector. And base on that SW can get a direction. Is this a correct statement?

  2. edgarquintana

    After a close review on this method, i realized that

    dblConeData(3) ‘x direction
    dblConeData(4) ‘y direction


    Cos X
    Sin X

    Where X is the adjacent angle

    API help should have explain that section a little better.

    • Thanks for pointing that out. You can submit this kind of feedback to the API Help documentation team by clicking “Send feedback” in the top right of every API Help page in the local API Help. I’d encourage you to do this.

      Also, don’t forget that values used by the API are in meters and radians. If you need a mathematical equation for pi, since there is no pi variable in VBA, use:
      4 * Atn(1)

  3. edgarquintana

    How do you add a temporary body to an existing solid body?

    • After you turn the temporary body into a true feature using IPartDoc::CreateFeatureFromBody3, I think you’ll simply need to use the Combine feature via IFeatureManager::InsertCombineFeature. Good question.

      • edgarquintana

        I liked the method you use on lesson 7.5 better, where you created a mergebodies() function. That was really skillful.

        Taking advantage of your reply, I’m running now into an issue where my display3 method only works properly if I’m using RealView graphics mode. Any idea why is that?

        I took your macro from lesson 7.5 and modified it to my needs. But can’t tell why that’s happening.

        • Edgar, the MergeBodies() function I used with SpikeCreator in 7.5 can only be used when creating a macro feature. The body that resulted from the merge operation was set as the return value of the macro feature rebuild function, which is the actual feature body produced by the macro feature. But if you aren’t working with macro features, then you’ll have to use the Combine feature as described above.

          IBody2::Display3 must be dependent on the graphics card in some way. I’ll have to perform my own test to verify this.

Questions and Comments

You must be logged in to post a comment.