How to change the description of a newly created part?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm using an iLogic rule to start from an assembly, hide some features, then create a shrinkwrap to send to our clients. I'd also want to add a description of this newly created part programmatically. I'm using this page for help.
A quick summary of my actions to do is:
Master assembly > hide parts > make a shrinkwrap > save it with a name "hello.ipt" > change its description to "description"
My code looks like this:
'some unimportant code hiding some parts
Try Dim g_App As Inventor.InventorServer = ThisApplication Dim AssDoc As Inventor.AssemblyDocument= ThisDoc.Document ' Create a new part document that will be the shrinkwrap substitute Dim oPartDoc As PartDocument oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True) Dim oPartDef As PartComponentDefinition oPartDef = oPartDoc.ComponentDefinition Dim oDerivedAssemblyDef As DerivedAssemblyDefinition oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName) ' Set various shrinkwrap related options oDerivedAssemblyDef.RemoveInternalVoids = True 'oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsWorkSurface oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone) Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone) Dim oDerivedAss As DerivedAssemblyComponent oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef) Call oDerivedAss.BreakLinkToFile() ' Save the part Dim partname As String Dim partdescr As String partname = "hello.ipt"
partdescr = "description" ' ThisApplication.ActiveView.Fit ' ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute Call oPartDoc.SaveAs(ThisDoc.Path() & "\" & partname, False) iProperties.Value(partname, "Description") = partdescr Call oPartDoc.Save Catch ex As Exception ErrorMessage = "Error creating ipt file." End Try 'ThisDoc.Document.Close()
I've highlighted the parts most interesting to me.
My train of thought was: I want to use the iProperties.Value() function. But that needs addressing the newly created part somehow. Its name can be Part1, Part2, Part100, or something like this, so I cannot address it properly. First I need to save it with a name (hello.ipt), then I can use that name to set a description property. So I've placed the description command after the SaveAs command. After setting the description, I save it again.
This is not working right, and I really cannot understand why. Would anybody help me with this, or suggest me a better method of changing the description of a newly created part?
Thanks!