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: 

Parameter in VBA

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
akAMYTB
4898 Views, 9 Replies

Parameter in VBA

Hi All

 

I'm trying to transfer multible reference parameters from a derived part to into User Parameters of a new part, and I have run into several issues.

 

1: How do I get the parameters from the derived part? I've tried this:

 

Dim Doc As Document
Set Doc = ThisApplication.ActiveDocument

 

Dim Params As Parameters
Set Params = Doc.ComponentDefinition.Parameters

 

Dim DerivedParamTbl As DerivedParameterTable
Set DerivedParamTbl = Params.DerivedParameterTables.Item("Path of the derived part") ' I geuss this is very bad practice, since I hoping to use this marco for any derived part I want in th future. 

Dim DerivedParam As DerivedParameter
Set DerivedParam = DerivedParamTbl.DerivedParameters.Item("Length")

 

2: When I get the value of a numeric parameter, the value is scaled down by a factor 10 (the decimal jogs to the left - 100 becomes 10, 200 becomes 20 and so on). I'm having a message box write out the values, and it seems that the scaling talks place, when the value is retreived ( Please note, that the value in this case simply comes from another User Parameter. Since I'm not yet able to get the values from the derived parts referenced parameters, I'm just testing with User Parameters. See the attachements. I'm trying to transfer the values named CopyXXX to the ones called PasteXXX.). Another indication that the scaling takes place when the value is retrieved is that I can simply set the value in the "target parameter" by using a predefined interger variable. Please see the test code: 

 

Sub MakeAbox()

Dim Doc As Document
Set Doc = ThisApplication.ActiveDocument

Dim Params As Parameters
Set Params = Doc.ComponentDefinition.Parameters

Dim UserParams As UserParameters
Set UserParams = Params.UserParameters

Dim PasteDimParam As Parameter
Set PasteDimParam = UserParams.Item("PasteDim")

Dim CopyDimParam As Parameter
Set CopyDimParam = UserParams.Item("CopyDim")

Dim PasteTxtParam As Parameter
Set PasteTxtParam = UserParams.Item("PasteTxt")

Dim CopyTxtParam As Parameter
Set CopyTxtParam = UserParams.Item("CopyTxt")

Dim PasteBoolParam As Parameter
Set PasteBoolParam = UserParams.Item("PasteBool")

Dim CopyBoolParam As Parameter
Set CopyBoolParam = UserParams.Item("CopyBool")

MsgBox CopyDimParam.Value & vbNewLine & CopyTxtParam.Value & vbNewLine & CopyBoolParam.Value

Dim SomeNumber As Integer
SomeNumber = 1523

 

'PasteDimParam.Expression = CopyDimParam.Value  ' When using this line the Target parameter gets the scaled value

PasteDimParam.Expression = CopyDimParam.Value & " cm" ' When using this line the Target parameter gets the scaled value in the equation column, but gets "cheated" to set the right norminal value.
PasteDimParam.Expression = SomeNumber ' When using this line the Target parameter gets the variable "SomeNumber" holds.
'PasteTxtParam.Expression = CopyTxtParam.Value ' Gives me Run time error 5
PasteBoolParam.Expression = CopyBoolParam.Value

Doc.Update

End Sub

 

3: I can get a text parameter (check what the messages box says) , but I get a Run Time Error 5 when trying to "paste it" to the target parameter.

 

The purpose of making this is to quickly make a box design, with lid and bottom, with flat patterns for both depending on the bounding box of the derived part. 

 

Any help will be appreciated.

 

Cheers - Anders

Tags (2)
9 REPLIES 9
Message 2 of 10
Frederick_Law
in reply to: akAMYTB

In the part file with the parameters you want to share, open the parameter list.  There is a column "Export Parameter".  Check the parameter you want to share.  They will show up in the derived parts and they will update when changed.

Message 3 of 10
akAMYTB
in reply to: Frederick_Law


@Frederick_Lawwrote:

In the part file with the parameters you want to share, open the parameter list.  There is a column "Export Parameter".  Check the parameter you want to share.  They will show up in the derived parts and they will update when changed.


Thanks for the answer, but getting the parameter from the derived part into the new parts parameters list is not the issue. How do I get it's object in the macro?  

 

Message 4 of 10
akAMYTB
in reply to: akAMYTB

Adding info: 

 

Regarding issue no. 2. I have tested some other macros where I get the coordinates of different points in a part. When the values are displayed in a messagebox, the comma has moved one digit to the left. Say the point is at X 123, Y 456 and Z -789, the messagebox displays X 12,3, Y 45,6 and Z -78,9.

 

So, it seems that whenever I retreive a value from a dimension or parameter, this scaling occures. 

 

Any idea why?

Message 5 of 10
Frederick_Law
in reply to: akAMYTB

I believe API return all values in mm which is used internally with Inventor.

Message 6 of 10
torbjorn
in reply to: akAMYTB

The API uses uses cm as length unit, that is why you see the 'scaling'. 

 

Torbjørn

Message 7 of 10
MechMachineMan
in reply to: akAMYTB

Torbjorn is correct about the internal units being why you are seeing the scaling. It appears you are using "mm" as your units, but the values returned from internal API calls are in database units ("cm" in this case).

 

As for trying to get derived part parameters: The link is only 1 way; the parent part doesn't know it has a derived part made from it, but the derived part knows about it's parent.


--------------------------------------
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 8 of 10
BrianEkins
in reply to: akAMYTB

Here's a little VBA macro that demonstrates getting what you want.  You'll also need the units when creating the new parameters, otherwise you might have a parameter that represents an angle and you create it as a length.

 

Public Sub GetDerivedParams()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument

    Dim derivedTable As DerivedParameterTable
    For Each derivedTable In partDoc.ComponentDefinition.Parameters.DerivedParameterTables
        Debug.Print "Parameters derived from: " & derivedTable.ReferencedDocumentDescriptor.DisplayName
        Dim param As DerivedParameter
        For Each param In derivedTable.DerivedParameters
            Debug.Print "   " & param.Name & ", " & param.Value & ", " & param.Units
        Next
    Next
End Sub
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 9 of 10
akAMYTB
in reply to: BrianEkins

Hi Brian 

 

Sorry for my late reply. I've been away from the office for a while, but finally had the time to try this out. Exactly what I need. Thanks alot. 

 

Cheers - Anders

Message 10 of 10
daniel.puchta
in reply to: BrianEkins

Hi Brian,

thank you for your solution. Would it be possible to somehow get the original derived parameter name (like name of parameter to which is derived parameter linked to)?

Sometimes you have different names of derived parameter and "original parameter".

Thank you in advance

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report