How does one access assembly parts parameters using VBA?

How does one access assembly parts parameters using VBA?

Anonymous
Not applicable
2,201 Views
5 Replies
Message 1 of 6

How does one access assembly parts parameters using VBA?

Anonymous
Not applicable

All I have is iLogic or VBA.

 

Not VBA.Net. Straight inventor VBA.

 

How do you do this in VBA?

 

This obviously is iLogic

 

SyntaxEditor Code Snippet

Parameter("XSpacer11", "XspacerX") = -XOffset + TP

 What is the equivalent syntax using VBA?

 

Thanks

 

===============================================================

0 Likes
Accepted solutions (2)
2,202 Views
5 Replies
Replies (5)
Message 2 of 6

MechMachineMan
Advisor
Advisor

As an FYI,

 

iLogic is simply using calls in a "simplified" Vb.net environment

Internal/External Rules can be coded in iLogic or VB.Net

Macros must be coded in VBA.

 

The difference between VB.net and VBA is fairly minimal; there are some objects advanced users use that are accessible in VBA and not Vb.net and vice versa. Other than that, you need Set statements in vba, and do not have access to Try/Catch error handling in VBA.

 

Good luck.

 

 


--------------------------------------
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
0 Likes
Message 3 of 6

bshbsh
Collaborator
Collaborator
Accepted solution

AFAIK, there's no straight equivalent syntax for this. It would be something like this:

 

Set oComp = ThisApplication.ActiveEditDocument.ComponentDefinition.Occurrences.ItemByName("XSpacer11")
For each Item in oComp.Definition.Parameters
if Item.Name = "XspacerX" then
Item.Value = -XOffset + TP
exit for
end if

AFAIK there's no "ItemByName" function for Parameters, at least not in IV2014. But I could be wrong.

 

 

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

@bshbsh Thanks

 

I think that is close and kind of what I envisioned.

 

I get a compiler error, oComp "Not defined"

 

I searched the class library for ItemByName and got 4 hits.

 

None of them solved the error.

 

If I can just crack this issue of "getting to" my part parameters, then I could do anything.

 

0 Likes
Message 5 of 6

bshbsh
Collaborator
Collaborator

I get a compiler error, oComp "Not defined"

It's because you might have "Option Explicit" on, meaning you have to explicitly define all variables first - what I didn't do beacuse I used to remove the "option explicit". So you either remove it too, or define oComp first:

Dim oComp as ComponentDefinition
0 Likes
Message 6 of 6

Anonymous
Not applicable
Accepted solution

Thanks again bshbsh. 

 

You're right.

 

I found some code here that is very close to what I am after.

 

http://forums.autodesk.com/t5/inventor-customization/change-user-parameter-custom-property-with-vba/...

 

Thanks for getting me to look in the right places.

 

All I had to do was change User to Model and now I am able to at least debug.print all my parameters.

 

I'll see today if this gets me home.

0 Likes