iLogic script to write base unit to iproperty

iLogic script to write base unit to iproperty

williamRPTGK
Participant Participant
488 Views
2 Replies
Message 1 of 3

iLogic script to write base unit to iproperty

williamRPTGK
Participant
Participant

Hi, I am setting up our templates to work with a new PLM system and as part of this I want to have a custom iproperty that reflects the base unit on the part. I have read through similar forum posts and tried to implement the various solutions but I am now stuck. I currently have the script below:

baseUnit = ThisApplication.ActiveDocument.ComponentDefinition.BOMQuantity.Baseunits
iProperties.Value("Custom", "Base Unit") = baseUnit

This does work but only when a base unit other than "Each" is selected in the document properties. For example, set base unit to mm:

 

williamRPTGK_0-1631523803591.png

 

Run script and view iproperties:

 

williamRPTGK_1-1631523868129.png

 

And it works as I want. However if I set the document settings back to the default 'each' (which is what it will be 99% of the time):

 

williamRPTGK_2-1631523944960.png

 

Then when I run the iLogic rule I just get blank in the iproperty:

 

williamRPTGK_4-1631524039510.png

 

Any help appreciated. Please note I am after the base unit (not quantity). Running inventor 2021 with all available updates.

 

Thanks in advance.

0 Likes
Accepted solutions (1)
489 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @williamRPTGK.  The online documentation of the BOMQuantity.BaseUnits property, specifies that is only applies when BaseQuantity is set to a parameter, therefore it does not return anything when that is not the case.  Do you want your iLogic rule to write "Each" to the iProperty when this is the case?  If so, here is a fairly simple modification to your rule that should handle that situation:

Dim baseUnit As String = ThisApplication.ActiveDocument.ComponentDefinition.BOMQuantity.Baseunits
If String.IsNullOrEmpty(baseUnit) Then
	iProperties.Value("Custom", "Base Unit") = "Each"
Else
	iProperties.Value("Custom", "Base Unit") = baseUnit
End If

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

williamRPTGK
Participant
Participant

Worked perfectly - many thanks.

0 Likes