Inventor Customization

Inventor Customization

Reply
Valued Contributor
Holgarsson
Posts: 71
Registered: ‎04-07-2005
Message 1 of 4 (164 Views)
Accepted Solution

DerivedPartDefinition

164 Views, 3 Replies
01-24-2013 06:01 AM

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

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)

 

Valued Contributor
Holgarsson
Posts: 71
Registered: ‎04-07-2005
Message 2 of 4 (158 Views)

Re: DerivedPartDefinition

01-24-2013 11:15 AM 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.

 

 

Mentor
krieg
Posts: 176
Registered: ‎11-22-2009
Message 3 of 4 (150 Views)

Re: DerivedPartDefinition

01-24-2013 01:49 PM 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

 

 

Valued Contributor
Holgarsson
Posts: 71
Registered: ‎04-07-2005
Message 4 of 4 (141 Views)

Re: DerivedPartDefinition

01-25-2013 12:01 AM in reply to: 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)

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.