How to Convert Normal dimension into Driven Dimension using iLogic?

How to Convert Normal dimension into Driven Dimension using iLogic?

jeeva.scientist
Enthusiast Enthusiast
2,146 Views
8 Replies
Message 1 of 9

How to Convert Normal dimension into Driven Dimension using iLogic?

jeeva.scientist
Enthusiast
Enthusiast

I want to convert "normal dimension" into the "driven dimension" & vice versa using iLogic Code.

if I have so many dimension how to I pick a specific dimension to convert.

I want to convert the,

  • d0 into Driven Dimension
  • d1 into Normal Dimension

Picture1.png

 

0 Likes
Accepted solutions (1)
2,147 Views
8 Replies
Replies (8)
Message 2 of 9

JelteDeJong
Mentor
Mentor

Hi,

try running this iLogic rule and select a dimension.

Dim dimension As DimensionConstraint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchDimConstraintFilter, "Select dimension")
If dimension.Driven Then
	dimension.Driven = False
Else
	dimension.Driven = True
End If

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 9

jeeva.scientist
Enthusiast
Enthusiast

The code you gave works perfectly ( Working Proof  ), Thanks. It is not what I expected.

I sorry I did not explain my problem clearly let me explain clearly.

I don't want to pick the dimension with the mouse.

for example,

I have four dimensions,

  1. d0 (normal dimension)
  2. d1 (driven dimension)
  3. d2 (normal dimension)
  4. d3 (normal dimension)

I just want to change,

  • d0 > driven dimension
  • d1 > normal dimension
  • d1 = d1 + (d0/2)
  • d0 > normal dimension
  • d1 > driven dimension

 

0 Likes
Message 4 of 9

HideoYamada
Advisor
Advisor

Hello,

 

When the sketch is activated, You can access to the dimensions from :

 

ThisApplication.ActiveEditDocument.ActivatedObject.DimensionConstraints

Here ThisApplication.ActiveEditDocument.ActivatedObject is activated PlanarSketch object.

dim.PNG

 

If the sketch is not activated, you must specify the sketch to edit.

For example,

 

Set dcs = ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches(sketchNumber).DimensionConstraint

 

=====

Freeradical

 Hideo Yamada

 

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 5 of 9

Sergio.D.Suárez
Mentor
Mentor

Hello, here I show you an example of how to achieve what you want in a sketch identified as the first through the item.

 

 

Sub Convert_DimA()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oCD As ComponentDefinition
    Set oCD = oDoc.ComponentDefinition
    
    Dim oSketch As PlanarSketch
    Set oSketch = oCD.Sketches.Item(1)
    
    Dim oDim As DimensionConstraint

    For Each oDim In oSketch.DimensionConstraints
        If oDim.Parameter.Name = "d0" Then   ' Indicate the name of the parameter you want to do in the driven dimension
            oDim.Driven = True
        End If
    Next
    
End Sub

Sub Convert_DimB()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oCD As ComponentDefinition
    Set oCD = oDoc.ComponentDefinition
    
    Dim oSketch As PlanarSketch
    Set oSketch = oCD.Sketches.Item(1)
    
    Dim oDim As DimensionConstraint

    For Each oDim In oSketch.DimensionConstraints
        If oDim.Parameter.Name = "d0" Then  ' Indicate the name of the parameter you want to do not in the driven dimension
            oDim.Driven = False
        End If
    Next
    
End Sub

I hope this helps you to develop your code completely. regards

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 6 of 9

jeeva.scientist
Enthusiast
Enthusiast

Hello, thanks for your code. I made some change to suit my application. hear I attached a video, in that video, I have shown my requirement. But I did that in a long way.

I have used three separate rules to get what I need. is there a way to use just one rule to combine all three operations.

steps are,

  • Enter a new value for "d1" ( when -> "d0" is driven dim & "d1" is normal dim ),now the "d0" value is driven by the "d1" value.
  • In Rule0 > it converts "d1" to driven dim & "d0" to normal dim
  • In Rule2 > it execute a expression (d0 = d1 * 2) 'for the new value of "d1"
  • In Rule1 > it converts "d0" to driven dim & "d1" to normal dim  (reverse of Rule0, to bring it to original state)

 

 

 

Rule0:

	Dim oDoc As PartDocument
   	oDoc = ThisApplication.ActiveDocument
    Dim oCD As ComponentDefinition
   	oCD = oDoc.ComponentDefinition
    
    Dim oSketch As PlanarSketch
   	oSketch = oCD.Sketches.Item(1)
    
    Dim oDim As DimensionConstraint

    For Each oDim In oSketch.DimensionConstraints
        If oDim.Parameter.Name = "d1" Then   ' Indicate the name of the parameter you want to do in the driven dimension
            oDim.Driven = True
        End If
    Next
	
    For Each oDim In oSketch.DimensionConstraints
        If oDim.Parameter.Name = "d0" Then  ' Indicate the name of the parameter you want to do not in the driven dimension
            oDim.Driven = False
        End If
    Next

Rule2:

	d0 = d1 * 2
	InventorVb.DocumentUpdate()
	iLogicVb.UpdateWhenDone = True

Rule1:

	Dim oDoc As PartDocument
   	oDoc = ThisApplication.ActiveDocument
    Dim oCD As ComponentDefinition
   	oCD = oDoc.ComponentDefinition
    
    Dim oSketch As PlanarSketch
   	oSketch = oCD.Sketches.Item(1)
    
    Dim oDim As DimensionConstraint
	
	 For Each oDim In oSketch.DimensionConstraints
        If oDim.Parameter.Name = "d0" Then   ' Indicate the name of the parameter you want to do in the driven dimension
            oDim.Driven = True
        End If
    Next
	
    For Each oDim In oSketch.DimensionConstraints
        If oDim.Parameter.Name = "d1" Then  ' Indicate the name of the parameter you want to do not in the driven dimension
            oDim.Driven = False
        End If
    Next

Edit form:
Picture11.png

 

Thanks for your support.

0 Likes
Message 7 of 9

jeeva.scientist
Enthusiast
Enthusiast

Please a look at Message 6

I have used 3 different rules to make it work. 

I want to do it with just one rule.

thanks.

0 Likes
Message 8 of 9

jeeva.scientist
Enthusiast
Enthusiast
Accepted solution

Hello,

This question has been solved by @Sergio.D.Suárez  in the other post please follow the link below.

https://forums.autodesk.com/t5/inventor-forum/how-to-convert-normal-dimension-into-driven-dimension-...

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oSketch As PlanarSketch = oCD.Sketches.Item(1)
Dim oDim As DimensionConstraint

For Each oDim In oSketch.DimensionConstraints
    If oDim.Parameter.Name = "d1" Then oDim.Driven = True
	If oDim.Parameter.Name = "d0" Then oDim.Driven = False
Next

'd0 = d1 * 2
oCD.parameters("d0").value = oCD.parameters("d1").value *2

InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True

For Each oDim In oSketch.DimensionConstraints
    If oDim.Parameter.Name = "d0" Then oDim.Driven = True
	If oDim.Parameter.Name = "d1" Then oDim.Driven = False
Next

Working proof


 

Message 9 of 9

marianYKR2R
Explorer
Explorer
jeeva.scientist. Thank you very much. This is what I was looking for. Regards
0 Likes