Modify Custom Property Format on Multiple components - Same Parameter

Modify Custom Property Format on Multiple components - Same Parameter

cbenner
Mentor Mentor
2,424 Views
15 Replies
Message 1 of 16

Modify Custom Property Format on Multiple components - Same Parameter

cbenner
Mentor
Mentor

Is there any way that anyone knows of, to go into each part of an assembly (or a selected set) find a particular User Parameter, and set a Custom Property Format?

 

My example: In Frame generator assembly, I would like to change the same Parameter on multiple parts from Fractional to Decimal without having to open each part individually.

 

Many thanks in advance for any help.

0 Likes
Accepted solutions (1)
2,425 Views
15 Replies
Replies (15)
Message 2 of 16

MechMachineMan
Advisor
Advisor
Yes. Open each part. Access the parameters. Use a try/catch to try and find the named one. If found, use the CustomPropertyFormat property/method, change the specific value to kFractional display or whatever it needs to be.

--------------------------------------
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
0 Likes
Message 3 of 16

MechMachineMan
Advisor
Advisor

Partial sample:

 

Dim oCompDef As ComponentDefinition
oCompDef = ThisApplication.ActiveDocument.ComponentDefinition

oUserP=oCompDef.Parameters.UserParameters

Dim oFormat As CustomPropertyFormat

Try
	For Each oParameter In oUserP
		If oParameter.Name=r

			oParameter.ExposedAsProperty=True
			With oParameter.CustomPropertyFormat
	
.Precision=Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision

'			ShowLeadingZeros=False
'			.ShowTrailingZeros=False
			.ShowUnitsString=True
                 End With
			Exit Try
		End If


	Next
Catch
     MsgBox("Error!")
End try

--------------------------------------
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
0 Likes
Message 4 of 16

Anonymous
Not applicable

I know this is a little different than what you need but it should get you pointed in the right direction. This inserts a multivalve parameter and also makes a custom property. I hope this helps in some way.    

 

SyntaxEditor Code Snippet

Imports  Inventor.UnitsTypeEnum


Dim oPartDoc As Document
oPartDoc = ThisDoc.Document

If oPartDoc.DocumentType = kPartDocumentObject Then

    Dim oPartCompDef As PartComponentDefinition
        oPartCompDef = oPartDoc.ComponentDefinition
        
Dim oParams As Parameters
        oParams=oPartCompDef.Parameters
                
        Dim oUserParams As UserParameters
        oUserParams=oParams.UserParameters       
        
        Dim oAwesomeParameter As Parameter                     
                    Try
            otester = oUserParams.Item("PK_Description")
            Catch
oInsulationType=oUserParams.AddByValue("PK_Description", "Description Override", kTextUnits) 
MultiValue.SetList("PK_Description", "Description Override", "Elbow", "Head", "Head With Extrusion", "Header With Swage", "Header Transition", "Header Extruded & Swage", "Header Extruded", "Manway", "Reducer (EEC)", "Reducer (CON)", "Shell For Vessels", "Bump Tee", "Tee", "Flat Bar", "Round Bar", "Closure", "Blind Flange", "Long Weld Neck Flange", "Semi-Ellipsoidal Head", "Lifting Lug", "Pipe", "Plate", "Soc-O-Let", "Weld-O-Let", "Thread-O-Let", "Tube, Round", "Tube, Square", "General REV")
            End Try
            End If

Parameter.Param("PK_Description").ExposedAsProperty = False
Parameter.Param("PK_Description").IsKey = False

iProperties.Value("Custom", "PK_Description")=Parameter.Param("PK_Description")

 

0 Likes
Message 5 of 16

ekinsb
Alumni
Alumni

I think this VBA code should do what you want.  You'll just need to change the name of the parameter and what it does for the custom property.

 

Public Sub UpdateCustomProperties()
    ' Get the open top-level assemby.
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    
    ' Get a list of all documents referenced by this assembly.
    ' This property will return everything at all levels.
    Dim refDocs As DocumentsEnumerator
    Set refDocs = asmDoc.AllReferencedDocuments
    
    ' Iterate through the documents.
    Dim doc As Document
    For Each doc In refDocs
        ' Look for part documents.
        If doc.DocumentType = kPartDocumentObject Then
            ' Look for a parameter named "Height".
            Dim params As Parameters
            Set params = doc.ComponentDefinition.Parameters
            
            On Error Resume Next
            Dim param As Parameter
            Set param = params.Item("Height")
            If Err.Number = 0 Then
                ' Set the custom property format.
                Dim propFormat As CustomPropertyFormat
                Set propFormat = param.CustomPropertyFormat
                
                propFormat.Precision = kFiveDecimalPlacesPrecision
                propFormat.Units = "ft"
                propFormat.PropertyType = kTextPropertyType
            End If
            On Error GoTo 0
        End If
    Next
End Sub

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 16

cbenner
Mentor
Mentor

Facing the same dilemma again today, with hundreds of parts to change.  Thanks for the help so far guys, but none of these have done the trick.

 

Bottom line is that this is a bug that needs fixing.  It's costing hours of labor. 

0 Likes
Message 7 of 16

AlexFielder
Advisor
Advisor

Is this still the same issue as per your OP @cbenner? Can you share a non-IP-containing example pack & go showing what is or isn't happening?

0 Likes
Message 8 of 16

cbenner
Mentor
Mentor

Yes, same issue.  It has been brought to Autodesk attention, but the fix seems to be slow in coming.

 

Basic description:

All of my FG family tables are set to use fractional units.  You can place from Content Center and see that the units are correct.  You can populate a new frame design, with the same correct units.  But as soon as you modify a frame member, for whatever purpose, the units spontaneously change to decimal.  This leaves my BOM with mixed units.  The only fix right now is to open each part and change the "G_L" parameter back to fractional units.  Sometimes this means hundreds of parts.  The one I'm doing now, I've been working on since Monday.

 

Here is the link I sent Autodesk last summer showing the bug.  https://autode.sk/2Pfo2WL

0 Likes
Message 9 of 16

AlexFielder
Advisor
Advisor

I can see why that would be annoying infuriating. I'll bet you've had a bunch of users unaware that the change happens  on editing and now you've got 100s if not 1000s of drawings with wonky BOMs right?

 

Does it only happen with the "Powell" FG library family or with everything? (I don't have Inventor open otherwise I'd test the standard stuff myself)

0 Likes
Message 10 of 16

cbenner
Mentor
Mentor

@AlexFielder 

 

I would have to test that out.  We only use our read/write library because of part numbering.  Stand by, and sometime today I will test the behavior with the Read Only libraries.

 

We usually catch this, at the very latest, when it gets to the weld shop.  We use an expression in the BOM to get the welder his cut lengths.  So when he sees mixed units he comes to us for clarification.  Infuriating is one word for it.....

0 Likes
Message 11 of 16

AlexFielder
Advisor
Advisor

Hi @cbenner,

 

I just had a quick look using the ANSI (Read-only) libraries I have installed here in the UK and in Inventor 2019.3 I'm not seeing a switch from fractional to decimal values when you edit a frame member and choose a different size. Whichever setting (fractional or decimal) is set in the originally selected files seems to stay set regardless.

 

To ease your pain however, I've modified the VBA @ekinsb provided to create two rules:

"Fractional"

Public Sub Main
	Call UpdateCustomProperties()
End Sub

Public Sub UpdateCustomProperties()
    ' Get the open top-level assemby.
    Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    
    ' Get a list of all documents referenced by this assembly.
    ' This property will return everything at all levels.
    Dim refDocs As DocumentsEnumerator = asmDoc.AllReferencedDocuments
    
    ' Iterate through the documents.
    Dim doc As Document
    For Each doc In refDocs
        ' Look for part documents.
        If TypeOf(doc) Is PartDocument Then
            ' Look for a parameter named "G_L".
            Dim params As Parameters = doc.ComponentDefinition.Parameters
            
            On Error Resume Next
            Dim param As Parameter = params.Item("G_L")
            If Err.Number = 0 Then
                ' Set the custom property format.
                Dim propFormat As CustomPropertyFormat = param.CustomPropertyFormat
                
                propFormat.Precision = CustomPropertyPrecisionEnum.kEighthsFractionalLengthPrecision
                propFormat.Units = "in"
                propFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
            End If
            On Error GoTo 0
        End If
    Next
End Sub

And "Decimal":

Public Sub Main
	Call UpdateCustomProperties()
End Sub

Public Sub UpdateCustomProperties()
    ' Get the open top-level assemby.
    Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    
    ' Get a list of all documents referenced by this assembly.
    ' This property will return everything at all levels.
    Dim refDocs As DocumentsEnumerator = asmDoc.AllReferencedDocuments
    
    ' Iterate through the documents.
    Dim doc As Document
    For Each doc In refDocs
        ' Look for part documents.
        If TypeOf(doc) Is PartDocument Then
            ' Look for a parameter named "G_L".
            Dim params As Parameters = doc.ComponentDefinition.Parameters
            
            On Error Resume Next
            Dim param As Parameter = params.Item("G_L")
            If Err.Number = 0 Then
                ' Set the custom property format.
                Dim propFormat As CustomPropertyFormat = param.CustomPropertyFormat
                
                propFormat.Precision = CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
                propFormat.Units = "in"
                propFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
            End If
            On Error GoTo 0
        End If
    Next
End Sub

 I suppose you could push whichever one suits into the parent Assembly or perhaps the drawing template for new works and add a trigger that runs before save? (Or you could always switch to using Metric (mm) and the problem goes away long-term 😉 )

0 Likes
Message 12 of 16

cbenner
Mentor
Mentor

@AlexFielder 

 

The read only libraries family template is set to use decimals on G_L, right out of the box.  There would be no real way to test this without saving the family to a read-write and modifying the family template (which is what I did).  Is this the method you used in your testing?

 

Either way, thank you for the modified code, I will certainly give that a try and if it works.... problem solved!

0 Likes
Message 13 of 16

cbenner
Mentor
Mentor
Accepted solution

As far as the code goes on this topic, a combination of the two VBA codes posted earlier did the trick.  here is the completed, tested code:

 

Public Sub Main()
    Call UpdateCustomProperties
End Sub

Public Sub UpdateCustomProperties()
    ' Get the open top-level assemby.
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    
    ' Get a list of all documents referenced by this assembly.
    ' This property will return everything at all levels.
    Dim refDocs As DocumentsEnumerator
    Set refDocs = asmDoc.AllReferencedDocuments
    
    ' Iterate through the documents.
    Dim doc As Document
    For Each doc In refDocs
        ' Look for part documents.
        If doc.DocumentType = kPartDocumentObject Then
            ' Look for a parameter named "G_L".
            Dim params As Parameters
            Set params = doc.ComponentDefinition.Parameters
            
            On Error Resume Next
            Dim param As Parameter
            Set param = params.Item("G_L")
            If Err.Number = 0 Then
                ' Set the custom property format.
                Dim propFormat As CustomPropertyFormat
                Set propFormat = param.CustomPropertyFormat
                
                propFormat.Precision = CustomPropertyPrecisionEnum.kEighthsFractionalLengthPrecision
                propFormat.Units = "in"
                propFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
            End If
            On Error GoTo 0
        End If
    Next
End Sub

Thanks to @AlexFielder  & @ekinsb  for pointing me in this direction.

Message 14 of 16

sebastien.forman
Advocate
Advocate

hello, if you change this propriety of frame before creation of frame part, you will have the format you want.

I hope that can help you

Capture.JPG

0 Likes
Message 15 of 16

AtNicksLLC
Participant
Participant

Just a note for anyone using this on later versions of VB.net  Let and Set are no longer recognized in this code. Simple fix, just delete these words and it works great. Thanks to all who have shared, saved a bunch of clicks and time.

0 Likes
Message 16 of 16

g_v_rooy
Contributor
Contributor

Changed the Macro a little bit.

Instead of inches it is now in mm and decimals is set to zero.

 

Public Sub Main()
Call UpdateCustomProperties
End Sub

Public Sub UpdateCustomProperties()
' Get the open top-level assemby.
Dim asmDoc As AssemblyDocument
Set asmDoc = ThisApplication.ActiveDocument

' Get a list of all documents referenced by this assembly.
' This property will return everything at all levels.
Dim refDocs As DocumentsEnumerator
Set refDocs = asmDoc.AllReferencedDocuments

' Iterate through the documents.
Dim doc As Document
For Each doc In refDocs
' Look for part documents.
If doc.DocumentType = kPartDocumentObject Then
' Look for a parameter named "G_L".
Dim params As Parameters
Set params = doc.ComponentDefinition.Parameters

On Error Resume Next
Dim param As Parameter
Set param = params.Item("G_L")
If Err.Number = 0 Then
' Set the custom property format.
Dim propFormat As CustomPropertyFormat
Set propFormat = param.CustomPropertyFormat

propFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
propFormat.Units = "mm"
propFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
End If
On Error GoTo 0
End If
Next
End Sub