Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
tiago.pereiraGB2J9
369 Views, 4 Replies

How to create various bodies at the same time

Hi,

I am trying to create a lot of cylinders bodies in the same VBA code. I´ve found the sample code on AutoDesk site, but when I tried to create more than 1 solid body, it seems that create a surface body instead of solid. Does anyone have any idea about it? I´m attaching the VBA code and a picture of the output of my code.

Thanks so much!

Sub mymacro3()

    ' Create a new part document, using the default part template.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition

    ' Set a reference to the TransientBRep object.
    Dim oTransientBRep As TransientBRep
    Set oTransientBRep = ThisApplication.TransientBRep
    
    
    ' Create bottom and top points for the first cylinder.
    Dim oBottomPt As Point
    Set oBottomPt = ThisApplication.TransientGeometry.CreatePoint(0, 1, 0)
    
    Dim oTopPt As Point
    Set oTopPt = ThisApplication.TransientGeometry.CreatePoint(0, 3, 0)
	
	' Create bottom and top points for the second cylinder.
	
    Dim oBottomPt2 As Point
    Set oBottomPt2 = ThisApplication.TransientGeometry.CreatePoint(0, 5 ,0)
    
    Dim oTopPt2 As Point
    Set oTopPt2 = ThisApplication.TransientGeometry.CreatePoint(0, 7, 0)
    
    ' Create the cylinder body.
    Dim oCylinder As SurfaceBody
    Set oCylinder = oTransientBRep.CreateSolidCylinderCone(oBottomPt, oTopPt, 0.5, 0.5, 0.5)
	
    Dim oCylinder2 As SurfaceBody
    Set oCylinder2 = oTransientBRep.CreateSolidCylinderCone(oBottomPt2, oTopPt2, 0.5, 0.5, 0.5)
    
    ' Create a base feature with the result body.
	
    Dim oBaseFeature As NonParametricBaseFeature
    Set oBaseFeature = oCompDef.Features.NonParametricBaseFeatures.Add(oBody)
    
    Dim oBaseFeature2 As NonParametricBaseFeature
    Set oBaseFeature2 = oCompDef.Features.NonParametricBaseFeatures.Add(oCylinder)
       
    
 
    
End Sub