Hi
Can anyone help me derive multiple solids from a part. I use the code shown below but it seem as I only can get the first solid in the part that I am trying to derive from.
''More Code'''
' Create a new part document, invisibly.
oPartDoc = m_inventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
oPartDoc.UnitsOfMeasure.LengthUnits =UnitsTypeEnum.kMillimeterLengthUnits
' Derive the assembly into the part.
Dim oDerivedPrtDef AsDerivedPartDefinition
oDerivedPrtDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateDefinition(oTopDoc.FullDocumentName)
Call oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPrtDef)
'''More Code'''
How can I get all the solids from the part that I am deriving from?
Regards
Kari
Solved! Go to Solution.
Solved by Holgarsson. Go to Solution.
Sorry some of the code was missing. Please see more detail below.
''More Code'''
' Create a new part document, invisibly.
oPartDoc = m_inventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
oPartDoc.UnitsOfMeasure.LengthUnits =UnitsTypeEnum.kMillimeterLengthUnits
' Derive the assembly into the part.
Dim oDerivedPrtDef AsDerivedPartDefinition
oDerivedPrtDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateDefinition(oTopDoc.FullDocumentName)
Call oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPrtDef)
'''More Code'''
'Find any voids within the solid and delete them.
Dim oVoidFaces As FaceCollection
oVoidFaces = m_inventorApp.TransientObjects.CreateFaceCollection
Dim oShell As FaceShell
For Each oShell In oPartDoc.ComponentDefinition.SurfaceBodies.Item(1).FaceShells
If (oShell.IsVoid = True) Then
Dim oFace As Face
For Each oFace In oShell.Faces
oVoidFaces.Add(oFace)
Next
End If
Next
If oVoidFaces.Count > 0 Then
Call oPartDoc.ComponentDefinition.Features.DeleteFaceFeatures.Add(oVoidFaces)
End If
Dim oMatrix As Matrix
oMatrix = m_inventorApp.TransientGeometry.CreateMatrix()
Dim oBody As SurfaceBody
oBody = oPartDoc.ComponentDefinition.SurfaceBodies(1)
Dim oPartDocFinal As PartDocument
oPartDocFinal = m_inventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
oPartDocFinal.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits
oPartDocFinal.ComponentDefinition.Features.NonParametricBaseFeatures.Add(oBody, oMatrix)
'''More Code'''
What I want is to iterate through the solid bodies from 1 to i for the following lines:
"For Each oShell In oPartDoc.ComponentDefinition.SurfaceBodies.Item(1).FaceShells" and "oBody = oPartDoc.ComponentDefinition.SurfaceBodies(1)"
Please feel free to give your input.
The original code is taken from "Create a document that represents only the external boundary of my Part or Assembly" by Xiaodong Liang on the Manufacturing DevBlog.
Thanks.
Hello
So try to enclose your code with an iterate through the surface bodies.
Dim oSurfBody as SurfaceBody
Dim oShell as FaceShell For each oSurfBody in oPartDoc.ComponentDefinition.SurfaceBodies For Each oShell In oPartDoc.ComponentDefinition.SurfaceBodies.Item(1) .FaceShells If (oShell.IsVoid = True) Then Dim oFace As Face For Each oFace In oShell.Faces oVoidFaces.Add(oFace) Next End If Next If oVoidFaces.Count > 0 Then Call oPartDoc.ComponentDefinition.Features.DeleteFaceFeatures.Add(oVoidFaces) End If Dim oMatrix As Matrix oMatrix = m_inventorApp.TransientGeometry.CreateMatrix() Dim oBody As SurfaceBody oBody = oPartDoc.ComponentDefinition.SurfaceBodies(1) Dim oPartDocFinal As PartDocument oPartDocFinal = m_inventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True) oPartDocFinal.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits oPartDocFinal.ComponentDefinition.Features.NonParametricBaseFeatures.Add(oBody, oMatrix) next
Thanks for your answer.
I used the following work-around by setting the derived style to "kDeriveAsSingleBodyWithSeams" this leaves the derived part with only one solid, thus I do not have to iterate through the solids. See the example below.
' Derive the assembly into the part.
Dim oDerivedPartDef As DerivedPartDefinition
oDerivedPartDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateDefinition(oTopDoc.FullDocumentName)
'Set derive style options
oDerivedPartDef.DeriveStyle =DerivedComponentStyleEnum.kDeriveAsSingleBodyWithSeams
'options:
'kDeriveAsSingleBodyWithSeams
'kDeriveAsSingleBodyNoSeams
'kDeriveAsMultipleBodies
'kDeriveAsWorkSurface
Call oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef)