Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

assembly physical properties to clipboard

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
joel_wennerstrand
416 Views, 7 Replies

assembly physical properties to clipboard

Hi,

 

I am a total beginner of iLogic with no previous programming experience. But feel so excited when I discovered this in Inventor. 

 

What I am trying to achieve is to have the physical properties updated and copied to clipboard as soon as the properties change. It could be that I move a component in an assembly that effects the center of gravity and the inertia properties.  

 

Can someone help me with the code for this?

 

BR
Joel

Labels (3)
7 REPLIES 7
Message 2 of 8

You've picked a very difficult task to learn coding.

I can't find the command of the "Clipboard" button.

Message 3 of 8

I agree.  I had also tried to find the command behind that button before, but was not able to.  We do know the command behind the UPDATE button ("AppUpdateMassPropertiesCmd"), but not the Clipboard button.  That command does not appear to have been exposed to the iLogic or Inventor API system yet either.  However, we do have access to pretty much all the same data through the Inventor API system, so could most likely replicate what that button does by code.  Writing the code for that task would be a real pain though, and would likely require quite a lot of code.  We have access to most of the data you see on that Physical Properties tab through the MassProperties API object.  And we can get access to that MassProperties object within the ComponentDefinition of PartDocuments (PartComponentDefinition.MassProperties), AssemblyDocuments (AssemblyComponentDefinition.MassProperties), and through assembly components (ComponentOccurrence.MassProperties), and a few other specialty types.  Once you have a reference to that MassProperties object assigned to a variable within your code, you can begin extracting all the data you require from it, using its various Methods & Properties.  But keep in mind that the data you get from those methods & properties will be in 'database units' instead of 'document units' (if they are different).  So, you may need to convert the units of the values as needed, to see the values in the units you want.  Then as you are extracting the data you want, you can build a large String (text) that contains textual sentences which include the data, and format it as you would like to see it, similar to what you see when you paste that copied data into a Microsoft Word document.

 

The steps of copying the data to the system clipboard, and/or retrieving that data from the Clipboard, is likely the simplest steps of the whole process.  Below is an extremely simple example of pasting text type data to the Clipboard, then retrieving it again, then showing the retrieved data in a MessageBox.  You may notice that it does not try to correct my use of a capital E in the word Copied.

Clipboard.SetText("Text 2 B CopiEd!", TextDataFormat.Rtf)
sCopiedText = Clipboard.GetText(TextDataFormat.Rtf)
MessageBox.Show("The following text was copied to the Clipboard:  " _
& vbCrLf & sCopiedText, "Retrieved From System Clipboard")

I am specifying RTF format, because that is the specific format being used by the Clipboard button in the Physical Properties tab.  Here is a link to the online help page  which mentions that.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-877564AC-78CE-4216-9913-003A2DE8D698 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 8

I was thinking to use keyboard keys to tab to "Clipboard" then "click" it.

Message 5 of 8
WCrihfield
in reply to: Frederick_Law

Good idea, but possibly a bit unstable.  Here is my attempt at doing that by code.  The first 3 lines seem to work as planned, but the following lines were not working as planned.  They seem to be getting odd (unexpected) data.  But if I just run the rule with the first 3 lines, it seems to copy the right data to the Clipboard, then I can open a new, empty Microsoft Word document, and paste it in there, as planned.  Not sure why the clipboard retrieval step is not working right.  May be a timing related issue.  It may need to process a while longer before trying to get the data from the clipboard or something.  Might need to use a loop to wait a bit.

 

ThisApplication.CommandManager.ControlDefinitions.Item("AppiPropertiesWrapperCmd").Execute2(False)
System.Windows.Forms.SendKeys.SendWait("{RIGHT 6}{TAB 3}{ENTER}{TAB}{ENTER}{ESC}")
ThisApplication.UserInterfaceManager.DoEvents()
'Dim sMassPropsData As String = System.Windows.Forms.Clipboard.GetText(System.Windows.Forms.TextDataFormat.Rtf)
'Logger.Info(sMassPropsData)
'System.IO.File.WriteAllText("C:\Temp\MassProperties.txt", sMassPropsData, System.Text.Encoding.Unicode)
'Process.Start("notepad.exe", "C:\Temp\MassProperties.txt")

Edit:  Oh, and by the way...if you use those first three lines on a document that does not have any model mass yet, the UPDATE button will not be available, so the sequence of 3 tabs would go straight to the CLIPBOARD button, instead of the UPDATE button.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 8

Probably faster to get the data and send it to clipboard.

This is what's in clipboard:

 

Physical Properties for Frame-ASSY-MS
General Properties:
	Material:	{}
	Density:	0.000 g/cm^3
	Mass:	N/A
	Area:	N/A
	Volume:	N/A
Center of Gravity:
	X:	N/A
	Y:	N/A
	Z:	N/A
Mass Moments of Inertia with respect to Center of Gravity(Calculated using negative integral)
	Ixx        	N/A
	Iyx Iyy    	N/A	N/A
	Izx Izy Izz	N/A	N/A	N/A
Mass Moments of Inertia with respect to Global(Calculated using negative integral)
	Ixx        	N/A
	Iyx Iyy    	N/A	N/A
	Izx Izy Izz	N/A	N/A	N/A
Principal Moments of Inertia with respect to Center of Gravity
	I1:	N/A
	I2:	N/A
	I3:	N/A
Rotation from Global to Principal
	Rx:	N/A
	Ry:	N/A
	Rz:	N/A

 

Message 7 of 8
JelteDeJong
in reply to: Frederick_Law

You could recreate the code. Here is a start but it is finished.

Dim doc As PartDocument = ThisDoc.Document
Dim uom = doc.UnitsOfMeasure
Dim nl = System.Environment.NewLine
Dim tab As Char = "\u0009"

Dim material = doc.ComponentDefinition.Material
Dim massProps = doc.ComponentDefinition.MassProperties
Dim Ixx, Iyy, Izz, Ixy, Iyz, Ixz
massProps.XYZMomentsOfInertia(Ixx, Iyy, Izz, Ixy, Iyz, Ixz)

Dim I1, I2, I3
massProps.PrincipalMomentsOfInertia(I1, I2, I3)
Dim Rx, Ry, Rz
massProps.RotationToPrincipal(Rx, Ry, Rz)

Dim txt As New StringBuilder()
txt.AppendFormat("Physical Properties for {0}{1}", doc.DisplayName, nl)

txt.AppendLine("General Properties:")
txt.AppendFormat("{1}Material:{1}{2}{0}", nl, vbTab, material.Name)
txt.AppendFormat("{1}Density:{1}{2}{0}", nl, vbTab, material.Density)
txt.AppendFormat("{1}Mass:{1}{1}{2}{0}", nl, vbTab, uom.ConvertUnits(massProps.Mass, UnitsTypeEnum.kDatabaseMassUnits, UnitsTypeEnum.kDefaultDisplayMassUnits))
txt.AppendFormat("{1}Area:{1}{1}{2}{0}", nl, vbTab, massProps.Area)
txt.AppendFormat("{1}Volume:{1}{1}{2}{0}", nl, vbTab, massProps.Volume)

txt.AppendLine("Center of Gravity:")
txt.AppendFormat("{1}X:{1}{1}{2}{0}", nl, vbTab, massProps.CenterOfMass.X)
txt.AppendFormat("{1}Y:{1}{1}{2}{0}", nl, vbTab, massProps.CenterOfMass.Y)
txt.AppendFormat("{1}Z:{1}{1}{2}{0}", nl, vbTab, massProps.CenterOfMass.Z)

txt.AppendLine("Mass Moments of Inertia with respect to ???????? (Calculated using negative integral)")
txt.AppendFormat("{1}Ixx:{1}{1}{2}{0}", nl, vbTab, Ixx)
txt.AppendFormat("{1}Ixy Iyy:{1}{2} {3}{0}", nl, vbTab, Ixy, Iyy)
txt.AppendFormat("{1}Ixz Iyz Izz:{1}{2} {3} {4}{0}", nl, vbTab, Ixz, Iyz, Izz)

txt.AppendLine("Principal Moments of Inertia with respect to Center of Gravity:")
txt.AppendFormat("{1}I1:{1}{1}{2}{0}", nl, vbTab, I1)
txt.AppendFormat("{1}I2:{1}{1}{2}{0}", nl, vbTab, I2)
txt.AppendFormat("{1}I3:{1}{1}{2}{0}", nl, vbTab, I3)

txt.AppendLine("Rotation from Global to Principal:")
txt.AppendFormat("{1}R1:{1}{1}{2}{0}", nl, vbTab, Rx)
txt.AppendFormat("{1}R2:{1}{1}{2}{0}", nl, vbTab, Ry)
txt.AppendFormat("{1}R3:{1}{1}{2}{0}", nl, vbTab, Rz)


Clipboard.SetText(txt.ToString(), TextDataFormat.Text)

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 8 of 8

Thank you for all the great suggestions. 

 

The solution with this code worked just the way I wanted. thanks again. 

ThisApplication.CommandManager.ControlDefinitions.Item("AppiPropertiesWrapperCmd").Execute2(False)
System.Windows.Forms.SendKeys.SendWait("{RIGHT 6}{TAB 3}{ENTER}{TAB}{ENTER}{ESC}")
ThisApplication.UserInterfaceManager.DoEvents()

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report