iLogic - Batch insert Sheet Metal Thickness into Description

iLogic - Batch insert Sheet Metal Thickness into Description

andrewdroth
Advisor Advisor
1,166 Views
5 Replies
Message 1 of 6

iLogic - Batch insert Sheet Metal Thickness into Description

andrewdroth
Advisor
Advisor

I'm trying to make an iLogic rule that will sort through an assembly, and change the description of sheet metal parts to "=<Thickness> PL".

 

I found this thread that help for the sorting, and changing the custom parameter formatting, but I'm struggling making it work. 

https://forums.autodesk.com/t5/inventor-customization/ilogic-batch-part-parameter-editor-rule-in-ass...

 

This is what I have, it seems to run through the parts, but it doesn't seem to make the changes I'm looking for.

SyntaxEditor Code Snippet
'Define the open document
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
 
'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
     'look at only part files
     If partDoc.DocumentType = kPartDocumentObject Then
     'format file name
     Dim FNamePos As Long
     FNamePos = InStrRev(partDoc.FullFileName, "\", -1)
     Dim docFName As String
     docFName = Right(partDoc.FullFileName, Len(partDoc.FullFileName) - FNamePos)

          Dim userParam As UserParameter
          For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters
                If userParam.Name = "Thickness"
 
                      userParam.ExposedAsProperty = True

                     Dim cFormat As CustomPropertyFormat = userParam.CustomPropertyFormat
                     cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
                     cFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
                     cFormat.Units = "in"
                     iProperties.Value("Project", "Description")="=<Thickness> PL"
                 End If
           Next
 
     'rebuild to update the display
     partDoc.Update
     End If
Next

openDoc.Rebuild

Andrew Roth
rothmech.com

YouTube IconLinkedIn Icon


IV2025 Pro
Apple IIe Workstation
65C02 1.023 MHz, 64 KB RAM
Apple DOS 3.3
0 Likes
Accepted solutions (2)
1,167 Views
5 Replies
Replies (5)
Message 2 of 6

HermJan.Otterman
Advisor
Advisor
Accepted solution

Hello Andrew,

 

I changed it a little in VB.net so so code is a little different, but it should work in iLogic

 

the Line:  cFormat.precision, did not work for my, so I left it out. you have to look in to that. (I'm working with metric files)

 

the main problem was that you where looking in the User prameters, and the Thickness is not a user parameter!

 

'Define the open document

Dim openDoc As Document

openDoc = Thisapplication.ActiveDocument

'Look at all of the files referenced in the open document

Dim oDoc As Inventor.Document

For Each oDoc In openDoc.AllReferencedDocuments

'look at only part files

If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then

Dim oPartDoc As PartDocument = TryCast(oDoc, PartDocument)

Dim oCompdef As PartComponentDefinition = oPartDoc.ComponentDefinition

If oCompdef.Type = ObjectTypeEnum.kSheetMetalComponentDefinitionObject Then

 

'format file name

Dim FNamePos As Long

FNamePos = InStrRev(oPartDoc.FullFileName, "\", -1)

Dim docFName As String

docFName = Strings.Right(oPartDoc.FullFileName, Len(oPartDoc.FullFileName) - FNamePos)

Dim oParam As Inventor.Parameter

For Each oParam In oPartDoc.ComponentDefinition.Parameters

If oParam.Name = "Thickness" Then

oParam.ExposedAsProperty = True

Dim cFormat As CustomPropertyFormat = oParam.CustomPropertyFormat

cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType

'cFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision

cFormat.Units = "in"

 

Dim oDescription As Inventor.Property = oPartDoc.PropertySets("Design Tracking Properties").Item("Description")

oDescription.Value = "=<Thickness> PL"

'iProperties.Value("Project", "Description") = "=<Thickness> PL"

End If

Next

'rebuild to update the display

oPartDoc.Update()

End If

End If

'End If

Next

openDoc.Rebuild()

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 3 of 6

Owner2229
Advisor
Advisor
Accepted solution

Just a little adjustment to Herm's code:

 

 

' Define the open document
Dim aDoc As Document = ThisApplication.ActiveDocument
If aDoc Is Nothing Then Exit Sub
' Look at all of the files referenced in the open document
For Each oDoc As Inventor.Document In aDoc.AllReferencedDocuments
	' Look at the sheet metal parts only
	If oDoc.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
	Dim oCD As PartComponentDefinition = oDoc.ComponentDefinition
	' Format the file name. I don't realy see why would you need it here, so I'll comment it out
	'Dim FNP As Integer = InStrRev(oDoc.FullFileName, "\", -1)
	'Dim FName As String = Microsoft.VisualBasic.Mid(oDoc.FullFileName, FNamePos + 1)
	Dim oParam As Inventor.Parameter = oCD.Parameters.Item("Thickness")
	If oParam Is Nothing Then Continue For
	oParam.ExposedAsProperty = True
	Dim cFormat As CustomPropertyFormat = oParam.CustomPropertyFormat
	cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
	cFormat.Units = "in"
	Dim oDescription As Inventor.Property = oDoc.PropertySets("Design Tracking Properties").Item("Description")
	oDescription.Value = "=<Thickness> PL"
	' Update the document
	oDoc.Update()
Next
' Rebuild to update the display aDoc.Rebuild()

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
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
0 Likes
Message 4 of 6

andrewdroth
Advisor
Advisor

Thanks guys!

 

That did it.

 

I just added the formatting for fractional units and it works perfect now.

 

' Define the open document
Dim aDoc As Document = ThisApplication.ActiveDocument
If aDoc Is Nothing Then Exit Sub
' Look at all of the files referenced in the open document
For Each oDoc As Inventor.Document In aDoc.AllReferencedDocuments
	' Look at the sheet metal parts only
	If oDoc.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
	Dim oCD As PartComponentDefinition = oDoc.ComponentDefinition
	' Format the file name. I don't realy see why would you need it here, so I'll comment it out
	'Dim FNP As Integer = InStrRev(oDoc.FullFileName, "\", -1)
	'Dim FName As String = Microsoft.VisualBasic.Mid(oDoc.FullFileName, FNamePos + 1)
	Dim oParam As Inventor.Parameter = oCD.Parameters.Item("Thickness")
	If oParam Is Nothing Then Continue For
	oParam.ExposedAsProperty = True
	Dim cFormat As CustomPropertyFormat = oParam.CustomPropertyFormat
	cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
	cFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
	cFormat.Units = "in"
	Dim oDescription As Inventor.Property = oDoc.PropertySets("Design Tracking Properties").Item("Description")
	oDescription.Value = "=<Thickness> PL"
	' Update the document
	oDoc.Update()
Next
' Rebuild to update the display
aDoc.Rebuild()

Andrew Roth
rothmech.com

YouTube IconLinkedIn Icon


IV2025 Pro
Apple IIe Workstation
65C02 1.023 MHz, 64 KB RAM
Apple DOS 3.3
0 Likes
Message 5 of 6

andrewdroth
Advisor
Advisor

OK, so a change in plan.

 

The units need to be switched to metric.

 

The description format will be 'PL6' (=PL<Thickness>) 

 

I've changed the 

cFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
cFormat.Units = "in"

to

cFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
cFormat.Units = "mm"

But that doesn't seem to work. Any ideas?

 

This is the full code I'm trying.

'Define the open document
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
 
'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
     'look at only part files
     If partDoc.DocumentType = kPartDocumentObject Then
     'format file name
     Dim FNamePos As Long
     FNamePos = InStrRev(partDoc.FullFileName, "\", -1)
     Dim docFName As String
     docFName = Right(partDoc.FullFileName, Len(partDoc.FullFileName) - FNamePos)

          Dim userParam As UserParameter
          For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters
                If userParam.Name = "Thickness"
 
                      userParam.ExposedAsProperty = True

                     Dim cFormat As CustomPropertyFormat = userParam.CustomPropertyFormat
                     cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
                     cFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
                     cFormat.Units = "mm"
		     cFormat.ShowUnitsString=False
		     iProperties.Value("Project", "Description")="=PL<Thickness>"
                 End If
           Next
 
     'rebuild to update the display
     partDoc.Update
     End If
Next

openDoc.Rebuild

Andrew Roth
rothmech.com

YouTube IconLinkedIn Icon


IV2025 Pro
Apple IIe Workstation
65C02 1.023 MHz, 64 KB RAM
Apple DOS 3.3
0 Likes
Message 6 of 6

andrewdroth
Advisor
Advisor

Nevermind,

 

Somehow I edited the original non working code.

 

This works as it should now.

 

' Define the open document
Dim aDoc As Document = ThisApplication.ActiveDocument
If aDoc Is Nothing Then Exit Sub
' Look at all of the files referenced in the open document
For Each oDoc As Inventor.Document In aDoc.AllReferencedDocuments
' Look at the sheet metal parts only
If oDoc.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
Dim oCD As PartComponentDefinition = oDoc.ComponentDefinition
' Format the file name. I don't realy see why would you need it here, so I'll comment it out
'Dim FNP As Integer = InStrRev(oDoc.FullFileName, "\", -1)
'Dim FName As String = Microsoft.VisualBasic.Mid(oDoc.FullFileName, FNamePos + 1)
Dim oParam As Inventor.Parameter = oCD.Parameters.Item("Thickness")
If oParam Is Nothing Then Continue For
oParam.ExposedAsProperty = True
Dim cFormat As CustomPropertyFormat = oParam.CustomPropertyFormat
cFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
cFormat.Units = "mm"
cFormat.ShowUnitsString=False
Dim oDescription As Inventor.Property = oDoc.PropertySets("Design Tracking Properties").Item("Description")
oDescription.Value = "=PL<Thickness>"
' Update the document
oDoc.Update()
Next
' Rebuild to update the display
aDoc.Rebuild()

Andrew Roth
rothmech.com

YouTube IconLinkedIn Icon


IV2025 Pro
Apple IIe Workstation
65C02 1.023 MHz, 64 KB RAM
Apple DOS 3.3
0 Likes