Inventor Customization

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

DerivedPartDefinition

145 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

Valued Contributor
Holgarsson
Posts: 71
Registered: ‎04-07-2005
Message 2 of 4 (139 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 (131 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 (122 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)

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube