Change precision of alternate units using VBA

Change precision of alternate units using VBA

Anonymous
Not applicable
1,806 Views
10 Replies
Message 1 of 11

Change precision of alternate units using VBA

Anonymous
Not applicable
Sub DimPrecisionThree()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
   
    Dim oDim As Object
    If oDoc.SelectSet.Count = 0 Then
        MsgBox "No dimension selected!"
        Exit Sub
    End If
    
    Dim oObjColl As ObjectCollection
    Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
    
    'Add selection to object collector
    Dim oObj As Variant
    For Each oObj In oDoc.SelectSet
        oObjColl.Add oObj
    Next
    
    Set oDim = oDoc.SelectSet(1)
    If oDim.Type = kLinearGeneralDimensionObject Or kOrdinateDimensionObject Then
        For Each oDim In oDoc.SelectSet
            oDim.Precision = 3
            '##########Alternate unit precision goes here###############
        Next
    End If
    
    'Re-select existing selection
    For Each oObj In oObjColl
        oDoc.SelectSet.Select (oObj)
    Next
End Sub

Code changes precision of main unit on dimension. I do not know how to set precision to alternate unit on same dimension. This is equal to double clicking on dimension, then select second tab "Precision and tolerance" and change precision for "Alternate Unit".

0 Likes
Accepted solutions (1)
1,807 Views
10 Replies
Replies (10)
Message 2 of 11

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

I think there no API to set alternate unit in general dimension, you can create this as IDEA.

you only can set in style editor, and this is for all dimension.

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 3 of 11

Anonymous
Not applicable

I knew it. I just needed a confirmation. I do not know what drives Autodesk programmers, but common sense should be the first thing. Inventor is lacking in so many areas. Autodesk should consider this as a compliment.

0 Likes
Message 4 of 11

forbillian
Advocate
Advocate

Hi Danilo,

 

Thankyou for your code it has been very useful.

 

Could you possibly help me apply this precision edit to the following deviation tolerance values?

I am having trouble adapting it.

'deviation example

' Set a reference to the select set of the active document.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

' Find all selected occurrences and add them to an ObjectCollection.
Dim oDrawingDims As DrawingDimension

'Loop through all dimensions
For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions
'set Tolerance Method
oDrawingDims.Tolerance.SetToDeviation(1, - 1)

Next 

 

0 Likes
Message 5 of 11

Anonymous
Not applicable

Hi!

I think you have to put Call in front. Like this:

Call oDrawingDims.Tolerance.SetToDeviation(1, - 1)

Because, "SetToDeviation" is a method not a property.

Message 6 of 11

forbillian
Advocate
Advocate

Thanks for the response Danilo.

 

How do I use the call to access the precision value of the deviation tolerance limits? I am not sure how to do this?

 

Thanks for your assistance in advance.

0 Likes
Message 7 of 11

Anonymous
Not applicable

Forbilian,

I am not sure I understand your question. Give me an example of what you are trying to do.

0 Likes
Message 8 of 11

forbillian
Advocate
Advocate

Hi Danilo,

 

I am attaching a screen shot.

 

I want to be able to alter the precision to '0' on the dimensions that I add the deviation tolerance to, without changing the active dimension style.

 

If I was to do it manually I would change the primary tolerance to a value of '0' but I am struggling to

find access to this field using ilogic.

 

Does this clarify what I am trying to achieve?

 

Thanks for your response

 

 

 

0 Likes
Message 9 of 11

Anonymous
Not applicable

Forbilian,

This is how I do it:

Sub DimTolPrecisionOne()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
   
    Dim oDim As Object
    If oDoc.SelectSet.Count = 0 Then
        MsgBox "No dimension selected!"
        Exit Sub
    End If
    
    Dim oObjColl As ObjectCollection
    Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
    
    'Add selection to object collector
    Dim oObj As Variant
    For Each oObj In oDoc.SelectSet
        oObjColl.Add oObj
    Next
    
    Set oDim = oDoc.SelectSet(1)
    If oDim.Type = kLinearGeneralDimensionObject Or kOrdinateDimensionObject Then
        For Each oDim In oDoc.SelectSet
            oDim.TolerancePrecision = 1
        Next
    End If
    
    'Re-select existing selection
    For Each oObj In oObjColl
        oDoc.SelectSet.Select (oObj)
    Next
End Sub
Message 10 of 11

forbillian
Advocate
Advocate

Thank You Danilo,

 

Even though your example wasn't Exactly what I needed you I used one line from your code

which worked.   It seemed a bit too easy after all my searching, but I appreciate developers that share their knowledge & you helped me.   I am very grateful!

 

' Set a reference to the select set of the active document.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

' Find all selected occurrences and add them to an ObjectCollection.
Dim oDrawingDims As DrawingDimension
Dim oSSet As SelectSet = oDoc.SelectSet

'Loop through all dimensions'For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions
For Each oDrawingDims In oSSet'set Tolerance Method
oDrawingDims.Tolerance.SetToDeviation( 0.5, -0.5)
'THIS LINE IS WHAT I NEEDED vvvvvvv thankyou Danilo
oDrawingDims.TolerancePrecision = 0
'THIS IS WHAT I NEEDED ^^^^^^^ thankyou Danilo
Next 

 

Message 11 of 11

Anonymous
Not applicable

Forbillian, thank you for the kind words.