- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is an iLogic version of this. Open a new part and paste this into a new iLogic rule and it will add 2 solid cylinders, but it joins them into a single solid. I'm not sure if that is acceptable for your purposes?
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oPartDoc As PartDocument oPartDoc = ThisDoc.Document ' a reference to the component definition. Dim oCompDef As PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition ' a reference to the TransientBRep object. Dim oTransientBRep As TransientBRep oTransientBRep = ThisApplication.TransientBRep ' Create bottom and top points for the first cylinder. Dim oBottomPt As Point oBottomPt = ThisApplication.TransientGeometry.CreatePoint(0, 1, 0) Dim oTopPt As Point oTopPt = ThisApplication.TransientGeometry.CreatePoint(0, 3, 0) ' Create bottom and top points for the second cylinder. Dim oBottomPt2 As Point oBottomPt2 = ThisApplication.TransientGeometry.CreatePoint(0, 5, 0) Dim oTopPt2 As Point oTopPt2 = ThisApplication.TransientGeometry.CreatePoint(0, 7, 0) ' Create the cylinder body. Dim oCylinder As SurfaceBody oCylinder = oTransientBRep.CreateSolidCylinderCone(oBottomPt, oTopPt, 0.5, 0.5, 0.5) Dim oCylinder2 As SurfaceBody oCylinder2 = oTransientBRep.CreateSolidCylinderCone(oBottomPt2, oTopPt2, 0.5, 0.5, 0.5) 'join the 2 cylinders Call oTransientBRep.DoBoolean(oCylinder, oCylinder2, BooleanTypeEnum.kBooleanTypeUnion) ' Create a base feature with the result body. Dim oBaseFeature As NonParametricBaseFeature oBaseFeature = oCompDef.Features.NonParametricBaseFeatures.Add(oCylinder)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks so much for your reply @Curtis_Waguespack !
It works! Now I can create two solid bodies. But the ideal for me it´s to have different bodies. Telling you the main idea of the work is to build a hole model of an offshore platform, a frame structure. I was thinking about the problem in the last few days and building it with solid bodies doesn't seem to be the best way, because the model will be too large to work. Do you have any ideas for this?
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@tiago.pereiraGB2J9 wrote:
Thanks so much for your reply @Curtis_Waguespack !
It works! Now I can create two solid bodies. But the ideal for me it´s to have different bodies. Telling you the main idea of the work is to build a hole model of an offshore platform, a frame structure. I was thinking about the problem in the last few days and building it with solid bodies doesn't seem to be the best way, because the model will be too large to work. Do you have any ideas for this?
Thanks again!
Hi @tiago.pereiraGB2J9 ,
I don't have any ideas on the offshore platform or if this is the best approach.
But I took another look at one of the other API examples and extracted what we needed to work with your original 2 cylinder example, this version creates 2 separate solids.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oPartDoc As PartDocument oPartDoc = ThisDoc.Document ' a reference to the component definition. Dim oCompDef As PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition ' a reference to the TransientBRep object. Dim oTransientBRep As TransientBRep oTransientBRep = ThisApplication.TransientBRep ' Create bottom and top points for the first cylinder. Dim oBottomPt As Point oBottomPt = ThisApplication.TransientGeometry.CreatePoint(0, 1, 0) Dim oTopPt As Point oTopPt = ThisApplication.TransientGeometry.CreatePoint(0, 3, 0) ' Create bottom and top points for the second cylinder. Dim oBottomPt2 As Point oBottomPt2 = ThisApplication.TransientGeometry.CreatePoint(0, 5, 0) Dim oTopPt2 As Point oTopPt2 = ThisApplication.TransientGeometry.CreatePoint(0, 7, 0) ' Create the cylinder body. Dim oCylinder1 As SurfaceBody oCylinder1 = oTransientBRep.CreateSolidCylinderCone(oBottomPt, oTopPt, 0.5, 0.5, 0.5) Dim oCylinder2 As SurfaceBody oCylinder2 = oTransientBRep.CreateSolidCylinderCone(oBottomPt2, oTopPt2, 0.5, 0.5, 0.5) Dim nonParaDef As NonParametricBaseFeatureDefinition nonParaDef = oCompDef.Features.NonParametricBaseFeatures.CreateDefinition Dim bodyColl_1 As ObjectCollection bodyColl_1 = ThisApplication.TransientObjects.CreateObjectCollection Call bodyColl_1.Add(oCylinder1) nonParaDef.BRepEntities = bodyColl_1 nonParaDef.OutputType = kSolidOutputType Dim oBaseFeature1 As NonParametricBaseFeature oBaseFeature1 = oCompDef.Features.NonParametricBaseFeatures.AddByDefinition(nonParaDef) Try : oBaseFeature1.Name = "Base1" : Catch : End Try Dim bodyColl_2 As ObjectCollection bodyColl_2 = ThisApplication.TransientObjects.CreateObjectCollection Call bodyColl_2.Add(oCylinder2) nonParaDef.BRepEntities = bodyColl_2 nonParaDef.OutputType = kSolidOutputType Dim oBaseFeature2 As NonParametricBaseFeature oBaseFeature2 = oCompDef.Features.NonParametricBaseFeatures.AddByDefinition(nonParaDef) Try : oBaseFeature2.Name = "Base2" : Catch : End Try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you so much @Curtis_Waguespack!
This helps me. I´ll try to find a solution for the offshore plataform problem and when I have the anwers, I´ll post it here.
Thanks again for your time