iLogic in DWG: To select a dimension and assign to a user parameter in the model

iLogic in DWG: To select a dimension and assign to a user parameter in the model

RoyWickrama_RWEI
Advisor Advisor
1,470 Views
4 Replies
Message 1 of 5

iLogic in DWG: To select a dimension and assign to a user parameter in the model

RoyWickrama_RWEI
Advisor
Advisor

DWG.png

 

I need to assign the value of a selected dimension in the drawing to a user parameter in the model. Please see below.

DWG2.png

 

oDoc = ThisDoc.Document
oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

iProperties.Value(oModelDoc, "Custom", "Length_X") = "6' 8-1/4''"

I look forward to receiving help.

 

Thanks.

 

0 Likes
Accepted solutions (1)
1,471 Views
4 Replies
Replies (4)
Message 2 of 5

RoyWickrama_RWEI
Advisor
Advisor

I got help from the Inventor Customization Forum. Thanks.

I am getting it done with the rule (need to improve) shown below:

 

Sub Main()
oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
Dim oDoc As DrawingDocument = ThisDrawing.Document

    Dim oSheet As Sheet
    oSheet = oDoc.ActiveSheet
    Dim oView As DrawingView
    'oView = oSheet.DrawingViews.Item(1)
    Dim oGeneralDimensions As GeneralDimensions
    oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions

Dim oSSet As SelectSet = oDoc.SelectSet
If oSSet.Count = 0 Then
	MessageBox.Show("Select at least one dimension please", "DIM", _
	MessageBoxButtons.OK,MessageBoxIcon.Information)
	Exit Sub
Else
	i = 0
	For Each obj As Object In oSSet
	i = i + 1
		'filter dimensions, ignore other selected entities
		If TypeOf obj Is GeneralDimension Then
		'reference to the selected dimension
		Dim oDim As GeneralDimension = obj
		'refrence to the DimensionText object
		Dim oDimensionText As DimensionText = oDim.Text
			If i = 1 Then 
			oCust_iProperty = Length_X
			iProperties.Value(oModelDoc, "Custom", oCust_iProperty) = oDimensionText.Text
			MessageBox.Show("Cutom iProperty, " & oCust_iProperty  & "Updated!", "Title")
			End If
		End If
	Next
End If
'Beep
End Sub

Need help on followings:

1. Need to select the dimension while running the rule (not to run the rule after selecting dimension(s))

2. Need to assign the value of the selected dimension to a user parameter (say, Dim_X1)

Look forward to receiving help!

 

Thanks.

 

0 Likes
Message 3 of 5

MechMachineMan
Advisor
Advisor

1. Use the pick command then.

 

2. Ok, so you use the appropriate calls to assign the value to a parameter, as outlined in the multitude of examples out there.


--------------------------------------
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 4 of 5

peter.hamas
Autodesk
Autodesk
Accepted solution

Hello,

you could try this iLogic rule, hope it helps!

if you click on a dimension, the rule prompts you to enter user param name,
if you press OK the param is added to the Model and you can select another dimension,

cancel or entering empty string restarts the dimension picker
to halt the rule use the Escape button

Cheers, ~peter

Dim oDoc As Document
oDoc = ThisDrawing.ModelDocument

Dim oUserParams As UserParameters
oUserParams = oDoc.ComponentDefinition.Parameters.UserParameters

Dim oDim As Inventor.GeneralDimension
Do
	oDim = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "Select Dimension")
	If oDim Is Nothing
		Exit Do
	End If
	
	oParamName = InputBox("Please enter parameter name.", "iLogic")
	If oParamName = "" Then
		Continue Do
	End If
	
	If TypeOf oDim Is AngularGeneralDimension
		oUserParams.AddByValue(oParamName, oDim.ModelValue, UnitsTypeEnum.kRadianAngleUnits)
	Else
		oUserParams.AddByValue(oParamName, oDim.ModelValue, UnitsTypeEnum.kCentimeterLengthUnits)
	End If
	
Loop While oDim IsNot Nothing
Message 5 of 5

RoyWickrama_RWEI
Advisor
Advisor

When I am in the model (a large master sketch), I see I need to re-assign the value for a user parameter. Now, I open the parameter and go through the list of parameter names to find the parameter I need to revise.

 

I have the sketch already open and selected the dimension. I prefer to revise this parameter at this point without opening the parameters page from the ribbon.

 

Could you help. Thanks.

 

0 Likes