Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How can I update a Custom iProperty after cutting?

rprivittB3TTG
Enthusiast

How can I update a Custom iProperty after cutting?

rprivittB3TTG
Enthusiast
Enthusiast

I have been using an imported Unistrut STEP file. The original file is 240 inches in length. I use a "Cut" feature to change the length. I also automated this with a slide bar for the measured length with a local "Form". I then have an iLogic "Rule" that save the customized length with the Unistrut name + the LENGTH parameter.

On the Drawing Parts List, I show the sum of Mass for each part in the assembly.

 

The problem is, no matter how long I have reduced the Unistrut part length using the "Cut" feature, the Mass is always the same as the full 240 inch length.

 

I tried using this code below. But it doesn't update the iProperty Mass:

ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
myMass = iProperties.Mass

MessageBox.Show("Mass = " & myMass, "iLogic")

I have already created a bunch of Unistrut lengths and used them in a lot of assemblies. I wish I had just started from scratch and just change the length dimension instead of using a cut. But I am fairly far down the road now. I need to manually update all the existing parts in my Vault. The existing parts do not update. I have resorted to adding my own calculation in the iProperties Physical Mass field on every part. I would like to automate this process some how.

 

rprivittB3TTG_1-1632853320273.png

 

I have also tried entering in the iProperties Physical Mass field: .1575 * LENGTH; But that doesn't work for some reason.

 

0 Likes
Reply
Accepted solutions (1)
780 Views
13 Replies
Replies (13)

rprivittB3TTG
Enthusiast
Enthusiast

I found a way to update the Mass. I made a "Parameter": NewMASS = .1575 * LENGTH

rprivittB3TTG_0-1632854834907.png

Then I added this text to a Local "Rule" and named it "UPDATE MASS"

iProperties.Mass = NewMASS

 Works like a champ. Now, I just need an automated way to add this parameter and rule to all my parts.

0 Likes

WCrihfield
Mentor
Mentor

It sounds to me like you may need to dig into the actual MassProperties object of your 'model' documents, instead of just trying to pull from the iProperties.  The MassProperties object can be found under the PartComponentDefinition and the AssemblyComponentDefinition.

 

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

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

rprivittB3TTG
Enthusiast
Enthusiast

You are probably 100% correct. But I don't have a clue how to access those iLogic commands.

0 Likes

WCrihfield
Mentor
Mentor

Here is something you can use to get the proper Mass value from the MassProperties object, and in the document units too, instead of the default 'database' units.  It checks to see if the Mass has been overwritten, and if True, it sets this to False, so it will show the real/actual Mass value.  Then it updated the model document, so it will recalculate, if necessary.  Once it retrieves this data, I included a message that will pop-up and tell you the results.  Then it will write the value to the user parameter you have.  Then it will expose that user parameter as a custom iProperty, so you can access this value through the iProperties instead of the parameters.  However, this will be a 'custom' iProperty, not the standard one, because the standard one generally returns the Mass in 'database' units by default, unless you have overwritten it.  This way nothing needs to be overwritten, and can remain 'live'.

Here is the iLogic rule code:

 

'get the document to work with
oDoc = ThisDoc.Document
Dim oMassProperties As MassProperties
Dim oParams As Inventor.Parameters
If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oPDoc As PartDocument = oDoc
	oMassProperties = oPDoc.ComponentDefinition.MassProperties
	oParams = oPDoc.ComponentDefinition.Parameters
ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim oADoc As AssemblyDocument = oDoc
	oMassProperties = oADoc.ComponentDefinition.MassProperties
	oParams = oADoc.ComponentDefinition.Parameters
Else
	'If this document is not either a Part or Assembly, exit the rule
	Exit Sub
End If

'get this document's units of measure for Mass
oUM = oDoc.UnitsOfMeasure
oMassUnits = oUM.GetStringFromType(oUM.MassUnits)

'convert the Mass from 'database' units to document units
If oMassProperties.MassOverridden = True Then
	oMassProperties.MassOverridden = False
End If
oDoc.Update
oMass = oUM.ConvertUnits(oMassProperties.Mass, UnitsTypeEnum.kDatabaseMassUnits, oMassUnits)

MsgBox("Mass = " & oMass & " " & oMassUnits, vbInformation, "Mass Data")

Try
	'find the parameter
	oParam = oParams.Item("NewMASS")
	'make sure the units are correct
	oParam.Units = oMassUnits
	'update its value
	oParam.Expression = oMass.ToString
Catch
	'the parameter wasn't found, so create it
	oParam = oParams.UserParameters.AddByExpression("NewMASS", oMass.ToString, oMassUnits)
End Try

 

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

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

rprivittB3TTG
Enthusiast
Enthusiast

I just tried this code. It indeed creates a User Parameter and displays the Mass Property value.

 

However, It is still showing me the total Mass of the uncut part. The uncut part is 240 inches long and roughly 35 lbs. When I cut the part down to 24 inches, I am expecting the Mass to be recalculated to roughly 3.5 lbs. Thus, the reason I am using the formula of NewMASS = .1575 * LENGTH

 

How do I implement this formula into your code?

0 Likes

WCrihfield
Mentor
Mentor

OK.  So if you do a fresh resize of the model using your form's slider, then open your iProperties dialog box to the Physical tab, then click the Update button, it is not changing the Mass value being shown there, correct?  Have you tried clearing any overwritten value from that Mass text box, then redoing this process to see if it is any different, just in case the overwritten value is 'static'?  If you keep getting the same results, and the cut process isn't changing the Mass of the part, that is definitely a troublesome issue.

 

If you believe that equation is producing the proper Mass value for you, then I don't think you would need any iLogic at all.  All you would need to do is create that user parameter with that equation in it, then set that parameter to be exposed as a custom iProperty by clicking the checkbox in the 'Export Parameter' column of the parameters dialog box.  That automatically created a matching custom iProperty from that parameter.  That iProperty will automatically be updated every time the parameter's value changes.  But the update won't go the other way (updating the iProperty won't update the parameter).  You can then right-click on that parameter's row in the parameters dialog, then choose 'Custom Property Format...' to customize how you want the custom iProperty to be formatted/displayed.

 

If needed, it would be fairly simple to create an external iLogic rule that would:

  • create the user parameter (NewMASS)
  • set its equation (assuming the 'LENGTH' parameter already exists)
    • 'LENGTH' appears to be a 'Model Parameter', is it already named this way in all other models to be processed?
    • if not, but the parameter exists with a different name, we may have to deal with that in the code
  • expose that parameter as a custom iProperty
  • set the custom formatting for that custom iProperty

Does this sound more like what you would want/need going forward?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

rprivittB3TTG
Enthusiast
Enthusiast

Simple is better.

I guess I am having trouble with the simplest task. I cannot seem to create the user parameter "NewMASS" using iLogic code. I have to go inside the Paremeters Dialog box and create this manually. And of coarse, I have to do this before I set the formula using NewMASS. Yes, LENGTH is already a model parameter for this series of parts.

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

I've been running into a problem making this happen by iLogic too.  I believe the main problem is the different units we're trying to 'mix' together.  I was hoping to set the resulting user parameter's units to pounds (mass units), but this fails because you can't multiply a value in length units by a value in mass units.  The unit types are incompatible.  You can multiply the inches value by a unit-less value, but the result is in inches, not pounds.  And if you try to change the units to pounds afterwards, it changes the numerical value also.  Mass = Volume x Density.

 

In order to have the resulting parameter set to pounds units, and get a compatible result, you would have to have a unit-less representation of the 'LENGTH' parameter to multiply by.  I tried creating another user parameter, set to unit less units, then setting its equation to LENGTH.  It results in a larger numerical value (basically as if the inches had been converted to centimeters).  So, my next thought was to leave that NewMASS user parameter as Inches units, but then set the custom iProperty's units to Pounds, within the custom property formatting, but I found out that this is not an option.  The property's units must also be in length type units.

 

So, in conclusion, you either have to do a lot of work around to get a resulting parameter that is in pounds units, or just leave the results in inches, when doing it this way.  If I know, or could obtain the Area of the end profile of the extrusion, I could then multiply that by the length to get its true Volume.  Then multiply that by its Density to get its Mass.  That true Volume value could also be another user parameter, if you were considering going that route.

 

Here is the iLogic code to do the process at the end of the last post.  The resulting user parameter is just in inches instead of pounds, but I'm assuming you know how to deal with that from there.

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
	'run the custom Sub below on this part document
	CreateNewMASSParamAndProp(oPDoc)
End Sub

Sub CreateNewMASSParamAndProp(oPart As PartDocument)
	Parameter.UpdateAfterChange = True
	MultiValue.UpdateAfterChange = True
	Dim oParams As Parameters = oPart.ComponentDefinition.Parameters
	Dim oUParams As UserParameters = oParams.UserParameters
	oMassUnits = oPart.UnitsOfMeasure.MassUnits 'document units for Mass
	oLengthUnits = oPart.UnitsOfMeasure.LengthUnits 'document units for Length
	'make sure the model parameter named 'LENGTH' exists
	Dim oParam, oLENGTH As Inventor.Parameter
	Dim oMassMultiplier, oNewMASS As UserParameter
	For Each oParam In oParams
		If oParam.Name = "LENGTH" Then
			oLENGTH = oParam
		ElseIf oParam.Name = "MassMultiplier" Then
			oMassMultiplier = oParam
		ElseIf oParam.Name = "NewMASS" Then
			oNewMASS = oParam
		End If
	Next
	'if it did not find the 'LENGTH' parameter, let the user know then exit the rule
	If IsNothing(oLENGTH) Then
		MsgBox("The model parameter named 'LENGTH' could not be found.  Exiting Rule.", vbExclamation, "iLogic")
		Exit Sub
	End If
	
	'create or update the user parameter for the 'MassMultiplier'
	If IsNothing(oMassMultiplier) Then
		'oMassMultiplier = oUParams.AddByExpression("MassMultiplier", "0.1575", oMassUnits)
		oMassMultiplier = oUParams.AddByExpression("MassMultiplier", "0.1575", "ul")
	Else
		'oMassMultiplier.Units = oMassUnits
		oMassMultiplier.Units = "ul"
		oMassMultiplier.Expression = "0.1575"
	End If
	'assemble the new equation in one place, so we can use it in two places below
	oNewEquation = "MassMultiplier * LENGTH"
	
	If Not IsNothing(oNewMASS) Then
		'the user parameter 'NewMASS' was found, so make sure it is up-to-date
		'oNewMASS.Units = oMassUnits
		oNewMASS.Units = oLengthUnits
		oNewMASS.Expression = oNewEquation
	Else
		'the user parameter 'NewMASS' was not found, so create it
		Try
			'oNewMASS = oUParams.AddByExpression("NewMASS", oNewEquation, oMassUnits)
			oNewMASS = oUParams.AddByExpression("NewMASS", oNewEquation, oLengthUnits)
		Catch oEx As Exception
			MsgBox("Failed to create the 'NewMASS' user parameter." & vbCrLf & _
			oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "iLogic")
		End Try
	End If
	'expose the 'NewMASS' user parameter as a custom iProperty
	If Not IsNothing(oNewMASS) Then
		Try
			If Not oNewMASS.ExposedAsProperty Then oNewMASS.ExposedAsProperty = True
			oCPF = oNewMASS.CustomPropertyFormat
			oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
			oCPF.Units = oLengthUnits
			oCPF.Precision = CustomPropertyPrecisionEnum.kEightDecimalPlacesPrecision
		Catch oEx As Exception
			MsgBox("Failed to expose the 'NewMASS' user parameter as iProperty." & vbCrLf & _
			oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "iLogic")
		End Try
	End If
	If oPart.Dirty Then
		oPart.Update
		oPart.Save
	End If
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

GosponZ
Collaborator
Collaborator

Why you using step file. Would it be easier to make CC file unistrut with slots adaptive to length, and then make length you need as custom part. I'm using unistruts on daily basis and lot. Never had problem with update mass. If so rebuild and update mass. I don't think you need ilogic code for that purpose. Just my 2c.

0 Likes

rprivittB3TTG
Enthusiast
Enthusiast
You are absolutely correct. I had just started working at this place, when my supervisor advised me to download STEP files for quicker throughput. Against my better judgement and years of experience, I did just that. I quickly realized that I had to create a routine to cut the length.

It all worked fine. Until I noticed the Mass wasn't correct in the Parts Table. By this time, I had already created about 150 different cut lengths of slotted and unslotted. These are used used in a multitude of designs now. As you know, reference failure will be a long chase to fix all the places these are used if I decide to use a better model.

On the other hand, I can start fresh on new assemblies with a new adjustable part.

For now, I need to get all these assembly models updated so that the Mass Properties are calculated correctly.
0 Likes

matt_jlt
Collaborator
Collaborator

Yep, it is weird your mass isn't updating automatically. can you upload one of the parts so we can have a look and try fix the issue. because you should definitely not need any code for masses to update.

0 Likes

A.Acheson
Mentor
Mentor

150 would be easier to find with or without ilogic and fix than working with a wrongly functioning part. You could simply make a rule to identify that part number or family  in a folder of files and replace that type of part with your new part.  I have used the extrude cut method for a walkway grip channel I wanted to look realistic but the pattern took too long to process by changing the length so it was a time saver to extrude cut to a shorter length. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

rprivittB3TTG
Enthusiast
Enthusiast

Attached is one of the saved versions that is cut off at 114". I have already fixed all of these that would not update the Mass Property.

 

I am going to model a new part with adjustable length. I will use that version for future assemblies.

 

As far as I am concerned, this topic is solved. But since you asked to examine the part, you may be able to discover what went wrong.

 

This part will launch a new form and execute two rules. One saves the new part with the LENGTH as part number to a specific folder.

0 Likes