Calculate Assembly Mass when Custom User Values exist

Calculate Assembly Mass when Custom User Values exist

arkelec
Collaborator Collaborator
615 Views
4 Replies
Message 1 of 5

Calculate Assembly Mass when Custom User Values exist

arkelec
Collaborator
Collaborator

I have programmed all parts & assemblies to have a custom property for mass, which reads the document iproperty for mass & uses it.

 

I have some items (Parts & Assemblies) which have a custom user value for mass, which I manually enter.  In order to use this, I also have a custom parameter which must be set to TRUE for the manual mass value to be used. 

 

Either the iproperty or the custom value for mass is used, subject to the state of the parameter.

 

Is there a way to force any assembly into which such items are placed to look for this custom parameter & where TRUE, use the custom mass value & what would be the best way to call it (a trigger?).

0 Likes
616 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

you could use an iLogic rule to write the custom parameter value to the iProperty if needed. If you do that Inventor will calculate the weight for you. rulewould look something like this:

If (CustomMass) Then
	iProperties.Mass = mass
Else
	iProperties.Mass = -1
	MsgBox(iProperties.Mass)
End If

 (The parameter 'mass' is the mass that should be used. The parameter 'CustomMass' is een boolean to set if you want the custom mass to use or not.)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 5

WCrihfield
Mentor
Mentor

I may be able to help you our on ths one.  I didn't see the name of your Custom iProperty in which you are storing the alternative Mass, so in my code I used "AltMass" in its place.  (I assumed this is a Custom iProperty, instead of a Parameter, due to the first line of your original post.)

This code would be in an external iLogic rule.  It would be triggered by a simple local rule (show below).

It basically loops through each ComponentOccurrnece and, based on how its Parameter is set, adds either its "AltMass" or its regular Mass to the main Assembly's "AltMass" custom Property.  I hope this is what you were trying to do.

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Assembly Documents.",vbOK, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oUParams As UserParameters = oADef.Parameters.UserParameters
Dim oACustMass As UserParameter = oUParams.Item("CustomMass") 'Boolean type
Dim oAMass As Double = iProperties.Mass
Dim oAAltMass As Double = iProperties.Value("Custom","AltMass")

Dim oOccADef As AssemblyComponentDefinition
Dim oOccPDef As PartComponentDefinition
Dim oOccDoc As Document
Dim oOccCustMass As UserParameter
Dim oOccMass As Double
Dim oOccAltMass As Double

Dim oOccs As ComponentOccurrences = oADef.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
	If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		oOccADef = oOcc.Definition
		oOccDoc = oOcc.Definition.Document
		oOccCustMass = oOccADef.Parameters.UserParameters.Item("CustomMass")
		If oOccCustMass.Value = True Then
			'Assuming your Custom iProperty for the manual mass is named "AltMass"
			oOccAltMass = oOccDoc.PropertySets.Item("Inventor User Defined Properties").Item("AltMass").Value
			oAAltMass = oAAltMass + oOccAltMass
		ElseIf oOccCustMass.Value = False Then
			oOccMass = oOccDoc.PropertySets.Item("Design Tracking Properties").Item("Mass").Value
			oAAltMass = oAAltMass + oOccMass
		End If
	End If
Next

 

 

 

Your local rule will look like this:

 

oDV = CustomMass
iLogicVb.RunExternalRule("TheNameOfYourExternalRule")

 

It will automatically be triggered any time the value of the local "CustomMass" parameter changes.

If need be, I can include some code at the beginning of this external rule that checks for this local rule, and creates it if not found.

 

If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.

 

Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • MessageBox, InputBox, and InputListBox Size & Format Options Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5

arkelec
Collaborator
Collaborator
Thanks for your reply. I haven't got time to test this right now, but will do so in the next week or so & report back.
0 Likes
Message 5 of 5

arkelec
Collaborator
Collaborator
Thanks for that. I'm still limping on with the code I have already running & due to other pressures, can't look at this at the moment.

I'll update once I have time (hopefully next week).
0 Likes