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: 

Ilogic "Calculate Square Footage"

10 REPLIES 10
Reply
Message 1 of 11
MrAcam04
2998 Views, 10 Replies

Ilogic "Calculate Square Footage"

Hello All,

 

I was wondering if there was an ilogic rule already existing that will calculate the square footage in an assembly and all individual parts as well. I have setup custom iproperties (Length x Width) in my template file along with a "Square Foot" property as well. These properties will show up in all BOM's generated for each part. But in an assembly I may use a "Total Square Foot" property in order to show the calculated value for all parts associated.

 

Thank you all in advance for your time and effort

10 REPLIES 10
Message 2 of 11
Gruff
in reply to: MrAcam04

Hi,

 

With respect you haven't really defined your problem fully in your message.

 

Where do you want this Total Square Foot value to show?  Master Assembly?  Master Assembly Drawing? Some Form?

 

What will display it?  Drawing Note?  Title Block Note?  Parts List Entry?  Label in a Form?

 

What will cause this code to run?  Some Trigger like Save or Load?  A key press?  A button press?

 

 

iLogic may not be the proper solution depending on what youj want to acheive.

Message 3 of 11
Gruff
in reply to: Gruff

Looked into this a bit.

The following code will work in an ILogic Rule, but it is not pure iLogic code.  Until Autodesk publishes their iLogic Runtime Properties, Methods in some sort of help listing I have to fall back on pure VB.NET Code.

 

The following will return a total of area assuming 1) There is a custom iProperty called SQFT_AREA that is of a numeric type.

 

[code]

Option Explicit

Imports Autodesk.Inventor

Sub Main
  Dim oApp As Inventor.Application =  ThisApplication
  Dim oAssy As Inventor.AssemblyDocument = oApp.ActiveDocument
  Dim oSubDoc as Inventor.Document
  Dim TotalArea As Double = 0 
  Dim sNames as String
 
 For Each oSubDoc in oAssy.AllReferencedDocuments
    'Get Custom Properties (User Defined Properties)
   Dim oPropset As Inventor.PropertySet = oSubDoc.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
   Try  
      Dim PartArea As Double = oPropset("SQFT_AREA").Value
      sNames &= oSubDoc.FullFileName & "  " & PartArea & vbNewLine  
     TotalArea += PartArea
   Catch ee As Exception
      sNames &= oSubDoc.FullFileName & "  " & "???" & vbNewLine  
   End Try
 Next


   sNames &= vbNewLine
   sNames &= "Total Area is: " & TotalArea
 
    MessageBox.show(sNames)

    oAssy = Nothing
   oApp = Nothing
End Sub

[/code]

Message 4 of 11
MrAcam04
in reply to: Gruff

Thank you Gruff for sharing your knowledge with us.

Hope the information below will help.

 

Where do you want this Total Square Foot value to show?

We would like the value to show on a drawing sheet. We will create a custom symbol that will point to a custom iproperty called "Square Foot" (for parts only)

  

Master Assembly Drawing? Yes, This is where we would like ilogic to total all the square footage from each individual part of the assembly. We will generate another symbol and have it pull from a custom iproperty called "Total Square footage" from within the assembly. (for assemblies only)

 

What will display it?  A custom Symbol

 

What will cause this code to run?  Not to sure as of yet, the save feature can work as of now. A special key will work as well.

 

Break Down

Part File

custom iproperty "square foot"

 

Assembly File

custom iproperty "Total square foot"

 

Drawing View

Custom symbol-1 (parts only)

Custom symbol-2(assembly only) this will total all the parts that make up the assembly.

Message 5 of 11
Gruff
in reply to: MrAcam04

Based on what you saying I thing the code below placed in your Assembly Tempate would do the job.  You would have to have your master drawing template Note use the driving assembly custom property "total square feet".  BTW I noticed that you capialized the T in Total square feet but not the s in "square feet"  Remember you have to be consistent with this sort of thing as somethings are case sensitive.  (Actuivally all iLogic code is case sensitive.

 

All part files must have "square feet" and all assembly files must have "otal square feet"

 

[code]

 

Option Explicit

Imports Autodesk.Inventor

Sub Main
  Dim oApp As Inventor.Application =  ThisApplication
  Dim oAssy As Inventor.AssemblyDocument = oApp.ActiveDocument
  Dim TotalArea As Double = 0
 
  For Each oSubDoc as Inventor.Document in oAssy.AllReferencedDocuments
    ' Only process if document is a part document
    if oSubDoc.DocumentType = kPartDocument then
       'Get Custom Properties (User Defined Properties)
       Dim oPartPropset As Inventor.PropertySet = oSubDoc.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
       Try 
          Dim PartArea As Double = oPartPropset("square foot").Value
          ' Add part area to total area
          TotalArea += PartArea
       Catch ee As Exception
         ' Do not raise or display an error.  We assume all parts have a "square foot" custom property
       End Try
    End If
  Next

  ' Get Master Assembly Custom PropertySet
  Dim oAssyPropset As Inventor.PropertySet = oAssy.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
  Try
    ' Set Custom Property to total Area
    oAssyPropset("Total square feet").Value = TotalArea
  Catch
    ' Do not raise or display an error.  We assume the Master Assembly has  a "total square foot" custom property
  End Try

  oAssyPropset = Nothing
  oAssy = Nothing
  oApp = Nothing
End Sub

 

[/code]

Message 6 of 11
MrAcam04
in reply to: MrAcam04

We will test this out shortly, we will keep you posted

 

 Thank you very much

 

Just tried to run the code and received this error

 

Error on Line 16 : Name 'kPartDocument' is not declared.

 

Part

square foot

 

Assembly

total square feet

Message 7 of 11
Gruff
in reply to: MrAcam04

Do you have the:text

"Imports Autodesk.Inventor"

Line at the top of the code?

 

Looks like I made a typo.  In the code it should be kPartDocumentObject

 

(The full enumeraion namespace to kPartDocumentObject is Inventor.DocumentTypeEnum.kPartDocumentObject)

Message 8 of 11
MrAcam04
in reply to: MrAcam04

We were brain storming a little more yesterday, We think it would be much easier to just add a BOM for each part on the a sheet. When we select parts list then choose the part we want, it will generate a BOM with the following columns.

 

                                            (C)       (C)         (C)                (C)

Item | Qty. |  Description | Length | Width | Thickness | Square Foot

 

(C) = custom iproperties

 

Our basic goal:

Part File = to have ilogic automatically determine Square foot and add it to the column. Display the squre foot in a custom symbol.

 

Assembly File = same BOM structure as a part file

to have ilogic automatically add up all the Square Footage of each part. (maybe opening a dialogue that will display the answer, set a hot key to trigger the dialogue box) just an idea

Let me know your thoughts, Thank you

All opinions welcome

 

Message 9 of 11
Gruff
in reply to: MrAcam04

Here is the final working ilogic solution.  I have tested it extensively and it works fine.

Any further modification is up to you.

 

Format:HTML Format
Version:1.0
StartHTML: 165
EndHTML: 14573
StartFragment: 314
EndFragment: 14541
StartSelection: 314
EndSelection: 314

' This iLogic goes into your Assembly File Template.
'
Set the Trigger to Save.
'
Create a Drawing file with a view of the Assemby file.
'
Put a note in it. Set the note to use the Assembly File Custom property "total square feet"

' On Assembly save this code gathers all "square feet" custom propery values from the part files and pushes the total
'
into the Assembly custom property "total square feet"

Option Explicit

Imports Autodesk.Inventor

Sub Main
Dim oApp As Inventor.Application = ThisApplication
Dim oAssy As Inventor.AssemblyDocument = oApp.ActiveDocument
Dim TotalArea As Double = 0

For Each oSubDoc as Inventor.Document In oAssy.AllReferencedDocuments
' Only process if document is a part document
If oSubDoc.DocumentType = kPartDocumentObject Then
'Get Custom Properties (User Defined Properties)
Dim oPartPropset As Inventor.PropertySet = oSubDoc.PropertySets("Inventor User Defined Properties")
Try
Dim PartArea As Double = oPartPropset("square feet").Value
' Add part area to total area
TotalArea += PartArea
Catch ee As Exception
' Do not raise or display an error. We assume all parts have a "square foot" custom property
End Try
End If
Next

' Get Master Assembly Custom PropertySet
Dim oAssyPropset As Inventor.PropertySet = oAssy.PropertySets("Inventor User Defined Properties")
Try
' Set Custom Property to total Area
oAssyPropset("total square feet").Value = TotalArea
Catch
' Do not raise or display an error. We assume the Master Assembly has a "total square foot" custom property
End Try

oAssyPropset = Nothing
oAssy = Nothing
oApp = Nothing

'Remove the following when doen testing
MessageBox.show(TotalArea.ToString & " SqFt of parts in the assembly")
End Sub

Message 10 of 11
MrAcam04
in reply to: Gruff

Sorry for the delay, I was out of town for a few weeks.

 

Thank you for providing us with the code.

 

When we set everything up it doesn't total anything up. We must be missing something along the way.

 

Part File

custom property: square feet (numeric)

(no code)

 

Assembly File

custom property: total square feet (numeric)

(added code)

 

Drawing File

sketch symbol : square feet

sketch symbol : total square feet

(no code)

 

 

Message 11 of 11
Gruff
in reply to: MrAcam04

After running it did you open the assembly file's custom iProperties and look at the value for "total square feet"?

That is all this code does. 

 

It is up to you to attach that property to some display mecanism in your master assembly drawing.

 

One way you can do this is the same way you attach iProperties to your title block.  This part is not programming just a feature of Inventor.

 

If the iProperty is not being totaled and the iLogic program is not erroring out then something is not right about your iProperties.

I do not know what.  either they are not named exactly as is shown in the code or Perhaps you made them Text instead of Numeric.

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

Post to forums  

Autodesk Design & Make Report