How to change the description of a newly created part?

How to change the description of a newly created part?

francesco.dinh
Advocate Advocate
697 Views
6 Replies
Message 1 of 7

How to change the description of a newly created part?

francesco.dinh
Advocate
Advocate

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!

 

0 Likes
698 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor

try in reverse:

 

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 partname As String
Dim partdescr As String
partname = "hello.ipt"
partdescr = "description"

iProperties.Value(partname, "Description") = partdescr

    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
	
'    ThisApplication.ActiveView.Fit
'    ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
    Call oPartDoc.SaveAs(ThisDoc.Path() & "\" & partname, False)
	
	Call oPartDoc.Save
Catch ex As Exception
        ErrorMessage = "Error creating ipt file."
End Try
'ThisDoc.Document.Close()

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 7

francesco.dinh
Advocate
Advocate

Nope, it's not working 😕 thanks though! I think it needs to create the shrinkwrap before being able to write information in it.

0 Likes
Message 4 of 7

bradeneuropeArthur
Mentor
Mentor
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 partname As String
Dim partdescr As String
partname = "hello.ipt"
partdescr = "description"

Call oPartDoc.SaveAs(ThisDoc.Path() & "\" & partname, False) iProperties.Value(partname, "Description") = partdescr 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 ' ThisApplication.ActiveView.Fit ' ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute ' Call oPartDoc.SaveAs(ThisDoc.Path() & "\" & partname, False) Call oPartDoc.Save Catch ex As Exception ErrorMessage = "Error creating ipt file." End Try 'ThisDoc.Document.Close()

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 5 of 7

francesco.dinh
Advocate
Advocate

Still not working... it's not changing the description, nor it's creating the shrinkwrap.

0 Likes
Message 6 of 7

MechMachineMan
Advisor
Advisor

I think the iProperties.Value(somefilename,,) call only works properly if the somefile is a child of the part you called the rule from. I think you are stuck either activating the document, or using the full API call for the iProperty.

 

 

'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()

    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)
oPartDoc.PropertySets("Design Tracking Information")("Description").Value = partdescr Call oPartDoc.Save Catch ex As Exception ErrorMessage = "Error creating ipt file." End Try 'ThisDoc.Document.Close()

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 7 of 7

francesco.dinh
Advocate
Advocate

Thank you for your reply! Unfortunately it's still not working.

 

My impression, but I might be wrong, is that the description is not assigned because it's taking too long to save. While it's creating and saving the shrinkwrap part, the description command runs and doesn't find any new file to save to. In the meantime, the save command has finished, but the instruction has alredy moved. Is this possible? Or is every line waiting for the previous one to end?

0 Likes