Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DerivedPartDefinition

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Holgarsson
397 Views, 3 Replies

DerivedPartDefinition

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

3 REPLIES 3
Message 2 of 4
Holgarsson
in reply to: Holgarsson

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.

 

 

Message 3 of 4
Ralf_Krieg
in reply to: Holgarsson

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

 

 


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
Message 4 of 4
Holgarsson
in reply to: Ralf_Krieg

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)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report