- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Deriving bodies to separate parts programattically
I am trying to build a script that does what the make components command does, but automates the passing of metadata from the multibody part to the individual parts. We design most of our weldments in multibody and then derive out to create an assembly that can be used for drawings and BOM's. The parameters that define the different pieces of steel (length width and thickness usually, but not always) live in the multibody part. I have a nomenclature system that links parameter names with body names, so that it is easy to know which parameter should go to which part, either manually or with a script.
So far I can either push the bodies out as base features in a script, thus losing connectivity, or derive the part into another part in a script, maintaining connectivity but unable to specify which body to choose and export programmatically. I suspect (hope?) that there is syntax in either methods or properties of the derived part definition options to add or remove individual entities to the derived part definition but I have so far been unable to either find or fake them. Below is the snippet in question. first and last line work fine, if I leave out the second line I get a derived part with all the bodies from the source part. But I cannot seem to find the structure that will get one specific body and push it to the derived part as a derived entity. (i.e. maintaining connectivity). Any advice or insight deeply appreciated.
'CodeStarts
'prior code, which all seems to work, iterates through bodies and associates them with parameters based on naming convention, and defines and creates target part
oDerivedPrtDef = oFinalCompDef.ReferenceComponents.DerivedPartComponents.CreateDefinition(oPartDoc.FullDocumentName)
oDerivedPrtDef.Entities.Add(oBody) ' this line is totally made up and throws errors, but gives the idea of what I need.
oFinalCompDef.ReferenceComponents.DerivedPartComponents.Add(oDerivedPrtDef)
'subsequent code saves new part with derived bits.
'Code Ends.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
HI, I don't have acces to Inventor right now, as Im at home, so I can't test it.
But did you try something like this below? (made from memory, so you may need to play with the statements - highlighted)
The idea in this is to run it for every component (as you do now, I suppose) and every time remove all components but one.
The "FirstComponent" name will come from the body name.
Dim oCurrentComponent As String = "FirstComponent" 'Here you should write the name of the first component
oDerivedPrtDef = oFinalCompDef.ReferenceComponents.DerivedPartComponents.CreateDefinition(oPartDoc.FullDocumentName) oFinalCompDef.ReferenceComponents.DerivedPartComponents.Add(oDerivedPrtDef)
Dim oCom As PartComponent
For Each oCom In oFinalCompDef.ReferenceComponents.DerivedPartComponents
MsgBox(oCom.Name) ' For testing purposes
If Not oCom.Name = oCurrentComponent Than
oCom.Remove
End If
Next
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Mike;
Thanks for the reply. After I posted, I dug a little deeper and found some more options in the api and came up with the below. Same basic approach as you suggested, make the derived part and then underive all but one body in each, and adjust metadata accordingly. (Again, this represents only the block concerned with creating the derived part. I have also however attached the entire rule below. Still need to write the bit to create the new assembly and put all the new parts in it.)
'StartCode
oPartDocFinal = CType(ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , False),PartDocument)
oFinalCompDef = oPartDocFinal.ComponentDefinition
oPartDocFinal.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kInchLengthUnits
oDerivedPrtDef = oFinalCompDef.ReferenceComponents.DerivedPartComponents.CreateDefinition(oPartDoc.FullDocumentName)
'oDerivedPrtDef.ExcludeAll
'oDerivedPrtDef.IncludeAllSolids=kDerivedIncludeAll'kDerivedIndividualDefined
oDerivedPrtDef.IncludeAllParameters=True
For each oDerivedEntity in oDerivedPrtDef.Solids
strEName = oDerivedEntity.ReferencedEntity.Name
msgBox (strEName)
If strEName <> strBName Then
oDerivedEntity.IncludeEntity = False
End If
Next
'oDerivedPrtDef.Solids.Add(oBody)
oFinalCompDef.ReferenceComponents.DerivedPartComponents.Add(oDerivedPrtDef)
For q = 0 to 3
oTargetParams = oFinalCompDef.Parameters.UserParameters
oTargetParameter = oTargetParams.AddByValue(aProperties(q),1,UnitsTypeEnum.kInchLengthUnits)
strPExpression = strBName & aPropAbbr(q)
oTargetParameter.Expression = strPExpression
Next q
'oPartDocFinal.ComponentDefinition.Features.NonParametricBaseFeatures.Add(oBody,oMatrix)
oPartDocFinal.SaveAs(strWorkPath & "\" & "PT_" & strBName & ".ipt", True)
'EndCode.