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: 

Derive iMate from multi body part

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
saseendrankombath
642 Views, 6 Replies

Derive iMate from multi body part

How to derive only referenced imates to the solid from multi body part.

6 REPLIES 6
Message 2 of 7

Please find attached result after deriving all imates thru api I want to import only the required ones

Message 3 of 7

When deriving a component, you can iterate through each derived entity and specify if it has to be included or not. You could check for iMateDefinition and use "iMateDefinition.ReferencedEntity" property to determine if you want to derive this iMate or not.

 

Here is a sample code that checks parameters:

 

Public Sub CreateDerivedPart()

    Dim doc As PartDocument
    Set doc = ThisApplication.ActiveDocument
    
    Dim derivedDoc As PartDocument
    Set derivedDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
        ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject), _
        True)
    
    Dim derivedPartComps As DerivedPartComponents
    Set derivedPartComps = derivedDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
       
    Dim derivedPartDef As DerivedPartUniformScaleDef
    Set derivedPartDef = derivedPartComps.CreateUniformScaleDef(doc.FullDocumentName)
    derivedPartDef.ScaleFactor = 0.75
    
    'derivedPartDef.ExcludeAll
    'derivedPartDef.IncludeAlliMateDefinitions
    'derivedPartDef.IncludeAllSurfaces
    derivedPartDef.IncludeAll
    
    Dim derivedEntity As DerivedPartEntity
    For Each derivedEntity In derivedPartDef.parameters
    
        If (TypeOf derivedEntity.ReferencedEntity Is parameter) Then
        
            Dim parameter As parameter
            Set parameter = derivedEntity.ReferencedEntity
            Debug.Print "Derived Parameter: " & parameter.name
        
            'Choose to include entity or not
            'derivedEntity.IncludeEntity = False
        End If
        
    Next
    
    derivedPartDef.DeriveStyle = kDeriveAsSingleBodyNoSeams
    
    Dim derivedComp As DerivedPartComponent
    Set derivedComp = derivedPartComps.Add(derivedPartDef)
    
End Sub

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 4 of 7

Thanks for your valued replay. But I need some more help from you. Can you please explain the correct usage of imateDefinition.ReferencedEntity to select the required imates. I was trying but unsuccessful on this. My actual requirement is ..... I have a multi body part with imates having same name but on different solid bodies of the multi body part. Then I am using make components to derive the solid bodies in to parts and to an assembly. After this I want to derive imates referenced to each solid body to the corresponding derived part. Please find the code which I was trying and the same derives all the imates. I need your help to solve this issue. Awaiting for your valued help.

 

Public Sub editDerived()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim derivedPartComp As DerivedPartComponent
Set derivedPartComp = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1)

Dim oderivdef As DerivedPartUniformScaleDef
Set oderivdef = derivedPartComp.Definition

Dim derivedEntity As DerivedPartEntity
For Each derivedEntity In oderivdef.iMateDefinitions
If (TypeOf derivedEntity.ReferencedEntity Is iMateDefinition) Then
Dim oiMate As iMateDefinition
Set oiMate = derivedEntity.ReferencedEntity
derivedEntity.IncludeEntity = True
End If
Next

oderivdef.DeriveStyle = kDeriveAsMultipleBodies
derivedPartComp.Definition = oderivdef

End Sub

 

Message 5 of 7

Here is the modified code, I am checking the included bodies status and set that to the derived iMateDefinition. In my test data set, the iMates are attached to faces, but I think the code will work for any brep entity:

 

Public Sub editDerived()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim derivedPartComp As DerivedPartComponent
    Set derivedPartComp = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.item(1)
    
    Dim oderivdef As DerivedPartUniformScaleDef
    Set oderivdef = derivedPartComp.Definition
    
    Dim derivedEntity As DerivedPartEntity
    For Each derivedEntity In oderivdef.iMateDefinitions
    
        Dim iMateDef As iMateDefinition
        Set iMateDef = derivedEntity.ReferencedEntity
    
        Dim bodyName As String
        bodyName = iMateDef.entity.Parent.name
    
        Dim derivedSolidEntity As DerivedPartEntity
        For Each derivedSolidEntity In oderivdef.Solids
            
            Dim surfbody As SurfaceBody
            Set surfbody = derivedSolidEntity.ReferencedEntity
            
            If surfbody.name = bodyName Then
                derivedEntity.IncludeEntity = derivedSolidEntity.IncludeEntity
            End If
        
        Next
       
    Next
    
    oderivdef.DeriveStyle = kDeriveAsMultipleBodies
    derivedPartComp.Definition = oderivdef
    
End Sub

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 6 of 7

Thanks a lot

This works well as I expected. Once again Thanks for helping.

 

With Regards,

Saseendran Kombath

Interplast Co. Ltd.,

Sharjah, U.A.E

Message 7 of 7

No problem.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

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

Post to forums  

Autodesk Design & Make Report