Conditional Tolerances/user symbols with iLogic or Macro

Conditional Tolerances/user symbols with iLogic or Macro

Anonymous
Not applicable
601 Views
5 Replies
Message 1 of 6

Conditional Tolerances/user symbols with iLogic or Macro

Anonymous
Not applicable

Hey guys!

I am hoping you all could point me in the right direction.

 

Here is the situation- some of our drawings require tolerancing that changes based on feature size. For example, features from 1" to 5" are +/-.03"; fromt 5" to 20" are +/- .1" and so on. currently I do this manually. Then we add a user symbol to the dimension (using shift and left click). I suppose this could be done using 2 seperate rules..

 

What i want to accomplish-

I want to be able to run a rule or macro that will go through all of my dimensions and set the tolerance for each one based on the tier-style tolerances as shown above. Then, i want a rule/macro to add a user symbol that is attached to the dimension. 

 

The problem for me is that I dont know where in the object model all the dimensions are stored. I want the rule to go through all of the dimensions, not just certain feature types or per view. I've found this online 

 

Dim oDef As PartComponentDefinition
				oDef = oDoc.ComponentDefinition
				Dim oHole(i) As HoleFeature
				oHole(i) = oDef.Features.HoleFeatures.Item(i)
				Dim oDiamParam(i) As Parameter
				oDiamParam(i) = oHole(i).HoleDiameter
				Dim oTol(i) As Tolerance
				oTol(i) = oDiamParam(i).Tolerance
				If oTol(i).ToleranceType() = 31233 Then ' If the hole currently has a default tolerance
					oTol(i).SetToFits(31244,("H6"),("")) ' Modify the hole tolerance
					HoleModCount = HoleModCount + 1 ' Bump the counter
					InventorVb.DocumentUpdate() ' Update Doc

but this is only for holes. How does one expand this to all features? Do I have to loop through all objects in the features collection object?

 

Thanks for your time,

D.M.

0 Likes
602 Views
5 Replies
Replies (5)
Message 2 of 6

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Hoping that below VBA code would help to set tolerance.

 

Sub Main()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As PartComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim oFeature As PartFeature
    For Each oFeature In oDef.Features
        Dim oParam As Parameter
        For Each oParam In oFeature.Parameters
            Dim oTol As Tolerance
            Set oTol = oParam.Tolerance
            
            Call oTol.SetToFits(kLimitsFitsShowTolerance, "H6", "")
        Next
    Next
    
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 6

Anonymous
Not applicable

@chandra.shekar.g

 

The issue with that is we often get stp files that dont have a model tree or features, they're just solids. This is what I've done as a macro (work in progress)

 

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Set oSheet = oDoc.ActiveSheet
Dim dimCollect As DrawingDimensions
Set dimCollect = oSheet.DrawingDimensions

Dim i As Integer
i = 1

Dim Dimension As DrawingDimension
Set Dimension = dimCollect.Item(1)
Dim DimUpperTol As Double
DimUpperTol = Dimension.Tolerance.upper

Dim NewUpperTol As Double
NewUpperTol = 0.001
'Dimension.Tolerance.upper = NewUpperTol

i can get it to spit out the dimensions and tolerances, but for some reason I can't CHANGE the tolerance. FYI this is a symmetric tolerance that I want to change (all of them are). The last line that is commented out always yields the error

 

"compile error:

 

wrong number of arguments or invalid property assignment"

 

 

0 Likes
Message 4 of 6

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide sample drawing with step file?

 

Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 6

Anonymous
Not applicable

See files attached. The ipt is an import of the stp file. 

I still cant figure out the code from above with the "wrong number of arguments or invalid property assignment" error. 

 

For some reason, I cannot attach the files

0 Likes
Message 6 of 6

Anonymous
Not applicable

So I figured this out, in case anyone had similar issues-

 

Public Sub CondTols()

Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
Dim dimCollect As DrawingDimensions
    Set dimCollect = oSheet.DrawingDimensions
    
Dim Tol1 As Double
    Tol1 = 1
Dim Tol2 As Double
    Tol2 = 2
Dim Tol3 As Double
    Tol3 = 3
Dim Tol4 As Double
    Tol4 = 4
    
Dim i As Integer
    i = 4
    
Dim Dimension As DrawingDimension
    Set Dimension = dimCollect.Item(i)
    
If Dimension.ModelValue <= 10 Then
    Dimension.Tolerance.SetToSymmetric (Tol1)
    End If
    
If Dimension.ModelValue > 10 And Dimension.ModelValue <= 20 Then
    Dimension.Tolerance.SetToSymmetric (Tol2)
    End If

 

It is still very much a work in progress but progress none the less

 

 

0 Likes