Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

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 - Batch Part Parameter Editor Rule in Assembly

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
1410 Views, 4 Replies

iLogic - Batch Part Parameter Editor Rule in Assembly

I was hoping I could get some advice about an iLogic rule I wrote for Inventor 2016.  My goal is to run it in an assembly, have it look at each part contained in that assembly, specify parameters (G_L, G_W, G_T) and have it configure them.  Because this configuration drives the final format of the BOM (which can vary from client to client) I often find myself tending to this task manually. I am fairly new to i Logic, but my thought process of accomplishing this is as follows:

 

1. look at only parts in the document

2. search for a "G_L" parameter

3. set it to export

4. set units to feet

5. Set fractional

6. Set 1/16 precision.

7. (FUTURE STEP) Continue to G_W and G_T parameters and repeat steps 3 thru 6

 

Below is the Rule I am struggling to troubleshoot:

 

 

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

 

'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
     'look at only part files
     If partDoc.DocumentType = kPartDocumentObject Then
     'format file name
     Dim FNamePos As Long
     FNamePos = InStrRev(partDoc.FullFileName, "\", -1)
     Dim docFName As String
     docFName = Right(partDoc.FullFileName, Len(partDoc.FullFileName) - FNamePos)

          Dim userParams As UserParameters
          For Each userParams In partDoc.ComponentDefinition.Parameters.UserParameters
          Next userParams

 

          p = Parameter.Param("G_L")

 

          p.ExposedAsProperty = True
          Dim cFormat As CustomPropertyFormat = p.CustomPropertyFormat
          cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
          cFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
          cFormat.Units = "ft"

 

     'rebuild to update the display
     partDoc.Rebuild
     End If
Next
iLogicVb.UpdateWhenDone = True

 

 

Here is the error I receive when I run the rule:

 

Error in rule: Rule0, in document: Assembly1

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.UserParameters'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2FF370FA-BB1C-4C92-BB10-06D94CC8F8F3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

 

 

Thank you!

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

'Define the open document

Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument

 

'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
     'look at only part files
     If partDoc.DocumentType = kPartDocumentObject Then
     'format file name
     Dim FNamePos As Long
     FNamePos = InStrRev(partDoc.FullFileName, "\", -1)
     Dim docFName As String
     docFName = Right(partDoc.FullFileName, Len(partDoc.FullFileName) - FNamePos)

          Dim userParam As UserParameters
          For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters

                If userParam.Name = "G_L" OR userParam.Name = "G_W" OR userParam.Name = "G_T"

 

                      userParam.ExposedAsProperty = True


                     Dim cFormat As CustomPropertyFormat = userParam.CustomPropertyFormat
                     cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
                     cFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
                     cFormat.Units = "ft"

                 End if

           Next

 

     'rebuild to update the display
     partDoc.Update
     End If
Next


openDoc.Rebuild

 


--------------------------------------
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
Anonymous
in reply to: MechMachineMan

Thank you so much for your response, @MechMachineMan!! I tried it out and it seems to run for a little longer than the ilogic I posted, but the  same error code persists =\

Message 4 of 5
MechMachineMan
in reply to: Anonymous

Take the s out of the line:

Dim userParam As UserParameters

to make

Dim userParam As UserParameter

--------------------------------------
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 5 of 5
Anonymous
in reply to: MechMachineMan

Thank you so much!!! @MechMachineMan

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

Post to forums  

Autodesk Design & Make Report