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: 

Change the Style of an existing dimension

12 REPLIES 12
Reply
Message 1 of 13
robmatthews
962 Views, 12 Replies

Change the Style of an existing dimension

Hey there. I'm chasing the syntax on what i hope is a very simple procedure.

We have a project for re-design and manufacture here (Australia) of a machine that has been designed and detailed in one of our US offices. For this reason, we will be wanting all dimensions in mm etc, rather than inch.

My intention is to open the idw(s), update the styles library (done, i think...), change the active standard to "AS Metric" (got the code sorted for that too), and then change all dimensions to AS Metric.

So far i have each of these 3 processes in a different sub, called from a master. But my problem is in changing the style. I see in the help file that i could change a dimension's style to match that of another existing style:

Set oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions.Item(1)

but I am having trouble setting is to the active style. What am i missing?

My module:

Sub ChangeStyle()
Dim oIDWDoc As DrawingDocument
Set oIDWDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oDim As DrawingDimension
Dim oDimStyle As DrawingStandardStyle
Dim oGeneralDimensions As GeneralDimension

Set oDimStyle = oIDWDoc.StylesManager.ActiveStandardStyle
For Each oSheet In oIDWDoc.Sheets
For Each oDim In oSheet.DrawingDimensions
Debug.Print "Style Name and Val: " & oDim.Style.Name & " " & oDim.ModelValue
If oDim.Style.Name <> "HC - AS Metric" Then
oDim.Style = oDimStyle.Style 'This is where i am falling over... Help???
End If
Next
Next
End Sub
=============================================
This is my signature, not part of my post.
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: robmatthews


The problem is that you're not setting the Style
property of the dimension to a DimensionStyle object.  Here's a corrected
version of your program.

 

Sub ChangeStyle()
    Dim oIDWDoc
As DrawingDocument
    Set oIDWDoc =
ThisApplication.ActiveDocument
   
    Dim
oSheet As Sheet
    Dim oDim As
DrawingDimension
    Dim oDimStyle As
DrawingStandardStyle
    Dim oGeneralDimensions As
GeneralDimension
    Set oDimStyle =
oIDWDoc.StylesManager.ActiveStandardStyle
   

    For Each oSheet In
oIDWDoc.Sheets
        For Each oDim In
oSheet.DrawingDimensions
           
Debug.Print "Style Name and Val: " & oDim.style.name & " " &
oDim.ModelValue
           

            If
oDim.style.name <> "Brian" Then   '"HC - AS Metric"
Then
               
oDim.style =
oDimStyle.ActiveObjectDefaults.LinearDimensionStyle
           
End If
        Next
   
Next
End Sub
--
Brian Ekins
Autodesk Inventor API Product
Designer

href="http://blogs.autodesk.com/modthemachine">http://blogs.autodesk.com/modthemachine
Message 3 of 13
robmatthews
in reply to: robmatthews

Fantastic, Thanks heaps. I never would have found that!!

Now I just have to capture, retain and re-place the tolerancing...
=============================================
This is my signature, not part of my post.
Message 4 of 13
robmatthews
in reply to: robmatthews

And apparently the below is also incorrect syntax:

'snip
If oDim.Tolerance.ToleranceType <> kDefaultTolerance Then
eToleranceType = oDim.Tolerance.ToleranceType
uTol = oDim.Tolerance.Upper
lTol = oDim.Tolerance.Lower
end if
'snip: condition: change the style
oDim.Tolerance.SetToLimits(eToleranceType, uTol, lTol) 'wrong again, Rob!!

Is this the same type of mistake as before? I'm well out of my depth, aren't I?
=============================================
This is my signature, not part of my post.
Message 5 of 13
Anonymous
in reply to: robmatthews

Hi Rob,

I would need to see a specific case where this problem shows up to be sure
but I suspect it's a problem with the tolerance type. You're getting the
tolerance type from the current dimension and using that directly to create
a Limits tolerance. The type of tolerance of the dimension may not be
compatible with a limits tolerance. I think you'll need to have some more
logic to decide with Set method of the Tolerance object to use to create the
correct tolerance.

-Brian
Message 6 of 13
Anonymous
in reply to: robmatthews

Try adding the Call keyword to this line of code:

Call oDim.Tolerance.SetToLimits(eToleranceType, uTol, lTol)

Sanjay-
Message 7 of 13
robmatthews
in reply to: robmatthews

Thanks for the suggestions Brian and Sanjay. When i get back to work after my annual leave, i will investigate further.
=============================================
This is my signature, not part of my post.
Message 8 of 13
robmatthews
in reply to: robmatthews

Brian & Sanjay, great help thanks. Sanjay, the Call keyword sorted out my immediate problem, and Brian, your commented prompted me to use a select...case statement to establish implement the correct type.

So now i grabbed all the enums possible that describe the tolerence type from the Help file. (I should mention that i am stuck in dinosaur land with IV9, yes verion 9).

But i have not found that there are methods to set each type to active. Below is what i have:

31245 Basic Tolerance
31233 Standard tolerance.
31236 DeviationTolerance. Call oDim.Tolerance.SetToDeviation(uTol, lTol)
31238 LimitLinearTolerance.
31242 LimitsFitsLinearTolerance.
31243 LimitsFitsShowSizeTolerance.
31244 LimitsFitsShowTolerance.
31241 LimitsFitsStackedTolerance. Call oDim.Tolerance.SetToFits(eToleranceType, uTol, lTol) 'Something Like this? Where uTol is HoleTolerance, and lTol is ShaftTolerance
31237 LimitsStackedTolerance Call oDim.Tolerance.SetToLimits(eToleranceType, uTol, lTol)
31239 MaxTolerance. How do you set to this type?
31240 MinTolerance. How do you set to this type?
31234 Tolerance override
31246 ReferenceTolerance
31235 Symmetric tolerance. Call oDim.Tolerance.SetToSymmetric(uTol)

Cheers muchly.
=============================================
This is my signature, not part of my post.
Message 9 of 13
Anonymous
in reply to: robmatthews

Look for the various "Set" methods on the Tolerance object (use the VBA
object browser).

MaxTolerance -> SetToMax
MinTolerance -> SetToMin

Sanjay-
Message 10 of 13
robmatthews
in reply to: robmatthews

Thanks Sanjay, but I might be out of luck here? See my attached screenshot of the Object Browser. Would any methods in this area have been added after release9? (I'm assuming that I'm looking in the "member" column for methods that apply to the Tolerance class?)
=============================================
This is my signature, not part of my post.
Message 11 of 13
Anonymous
in reply to: robmatthews

Added in Inventor 10.

Sanjay-
Message 12 of 13
robmatthews
in reply to: robmatthews

Ah, I'm fresh out of luck then. But thank you for your time.
=============================================
This is my signature, not part of my post.
Message 13 of 13

Hi Brian!

 

i try your rule but i have this error message?

odimstyle error.PNG

and this the rule i use

 

Dim oIDWDoc As DrawingDocument
oIDWDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oDim As DrawingDimension
Dim oDimStyle As DrawingStandardStyle
Dim oGeneralDimensions As GeneralDimension
oDimStyle = oIDWDoc.StylesManager.ActiveStandardStyle
For Each oSheet In oIDWDoc.Sheets
For Each oDim In oSheet.DrawingDimensions

Debug.Print ("Style Name and Val: " & oDim.style.Name & " " & oDim.ModelValue)

If oDim.style.Name <> "STD IMPERIAL (GD PRO)" Then
iProperties.Value("Custom", "test") = oDim.style.Name
oDim.Style = oDimStyle.ActiveObjectDefaults.LinearDimensionStyle
End If
Next
Next

 

Do you can help me?

 

 

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

Post to forums  

Autodesk Design & Make Report