How to derive only referenced imates to the solid from multi body part.
Solved! Go to Solution.
Solved by philippe.leefsma. Go to Solution.
Please find attached result after deriving all imates thru api I want to import only the required ones
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.
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
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.
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
No problem.
Regards,
Philippe.