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: 

Need iLogic help getting MassProperties

4 REPLIES 4
Reply
Message 1 of 5
karthur1
448 Views, 4 Replies

Need iLogic help getting MassProperties

I want to find the "exposed" surface area of my assembly.  Doing some searching, it seems that the "AssemblyDocument.ComponentDefinition.MassProperties.Area" will give the total area of the assembly. ( I am not sure if this is just the sum of all the parts or if this is actually the exposed surfaces.)

 

I am wanting to write this to a variable using iLogic and then print it to the screen just so I can tell if its what I want or not.  Having trouble doing that.

 

Here is the code I have so far.  There is a problem on line 10 (Reference to a non-shared member requires an object reference).  I can't figure out what I am doing wrong, but it is probably really simple for someone that knows squat about iLogic.

 

'Dim oAsmDoc As AssemblyDocument
'oAsmDoc = ThisApplication.ActiveDocument

'current document
doc = ThisDoc.Document
'unit manager of the document
oUOM = doc.UnitsOfMeasure
'get the value of Area
'surfaceArea = iProperties.Area
surfaceArea = AssemblyDocument.ComponentDefinition.MassProperties.Area
'round the value with 4 valid numbers (optional)
surfaceArea = Round(surfaceArea, 4)
'convert the value to a string with the unit of the document
surfaceArea = surfaceArea.ToString() + " " + oUOM.GetStringFromType(oUOM.LengthUnits) + "^2"
'update the custom property "Area" we created
'iProperties.Value("Custom", "Area") = surfaceArea
MessageBox.Show("Total Surface Area in SQ IN = " &surfaceArea,"Exterior Surface Area")

 

Any help greatly appreciated.

 

Kirk

 

4 REPLIES 4
Message 2 of 5
MechMachineMan
in reply to: karthur1

Things to consider: - Values pulled from Inventor are always database units, so care and often unit conversions are required to work with values in the unit you want.

 

- VBA and VB.net provide access to methods and properties through OBJECTS. ie; [OBJECT].Method or [OBJECT].Property

- Objects are only accessed in very few ways:

          - Assigning an object to another variable object; ie; oAsmDoc = ThisApplication.ActiveDocument

          - PreExisting Objects ie; VBA.Len()

          - New Objects ie; oInvApp = CreateObject("Inventor.Application")

 

- iLogic 'bastardizes' this in a way by providing many objects without having to think where they come from; ie; iProperties("Project", "Description") is actually a short version for saying [ApplicationObject].[Document Object].PropertySets("Design Tracking Properties")("Description").Value

 

- What this comes down to is that you should always know exactly what object you are wanting to point to/what object is returned whenever you see the ".".

 

- Why it didnt work for you - What specific object is just "AssemblyDocument" supposed to refer to? As you see in the first line, AssemblyDocument is actually a type and doesn't point to a specific object; just what kind of object it is. However, in the step below, ThisApplication is a pre-existing object that refers to the instance of the Inventor Application the rule is run in, which is why we can call it.

 

- In your snippet, you called Round() which is actually a short version of VBA.Round(). We don't need to specify VBA because it is the default object assigned to a method/property without the object indicated.

 

SyntaxEditor Code Snippet

Dim oAsmDoc As AssemblyDocument 
oAsmDoc = ThisApplication.ActiveDocument

'unit manager of the document
oUOM = oAsmDoc.UnitsOfMeasure

surfaceArea = oAsmDoc.ComponentDefinition.MassProperties.Area
MsgBox(oUOM.ConvertUnits(surfaceArea, "cm^2", "in^2") & " in^2") 

 

 


--------------------------------------
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
Message 3 of 5
karthur1
in reply to: MechMachineMan

Thanks for helping with the code.  However, that does not report what I was hoping.  There might not be a way to do this.

 

Take the assembly shown below.

 

block.jpg

 

This block measures 12in x 12in x 4.5in thick.  For the exposed surface area, it calculates to be 504in^2.  (144 front face, 144 back face, 54 on each edge face).  In the inventor iproperties it reports 1080 in^2 for the area.  This is the total area of each of the individual pieces (360in^2 x 3 pieces).

 

Is there a way to get the exposed surface area?

 

Thanks,

Kirk

Message 4 of 5
SašoPrijatelj
in reply to: karthur1

As far as I know there is no way to directly get exposed area.

 

But in this case you can simply get it if you create derived component and measure its total area.

-----------------------------------------------------------------------
AutoDXF - automatic flat pattern creation and batch export to DXF for Inventor

Please use "Accept as Solution" & give "Kudos" if this response helped you.
Message 5 of 5
karthur1
in reply to: SašoPrijatelj


@Anonymous wrote:

As far as I know there is no way to directly get exposed area.

 

But in this case you can simply get it if you create derived component and measure its total area.


I am aware of that, but I am trying to automate the process.  My ultimate goal is to have the exposed area shown on an idw

 

Thanks

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report