Use iLogic to Change Ord. Dimensions, General Dimensions & Thread / Hole Styles

Use iLogic to Change Ord. Dimensions, General Dimensions & Thread / Hole Styles

Anonymous
Not applicable
2,208 Views
4 Replies
Message 1 of 5

Use iLogic to Change Ord. Dimensions, General Dimensions & Thread / Hole Styles

Anonymous
Not applicable

 Gentleman,

 

 I am having an issue with the below code. I had it almost working and then I butchered it.

 

What I am trying to do is the following on all sheets of a Drawing.

- Do I need to write code to ignore the excluded sheet? There will only be a block that is automatically filled out with company information.

 

1. Change all existing general Dimensions to two style choices;  "ANSI - IN [MM]" & "ANSI - MM"

2. Change all existing Ordinate Dimensions to two different style choices; "ANSI - ORDINATE - IN [MM]" & "ANSI - ORDINATE - MM"

3. Change all existing hole and thread call-outs to follow these two choices; "ANSI - IN [MM]" & "ANSI - MM"

 

Items 1 and 2 can occur on the same drawing. what that means is:

 

4. "ANSI - IN [MM]" & "ANSI - ORDINATE - IN [MM]" can change at the same time

5. "ANSI - MM" & "ANSI - ORDINATE - MM" can change at the same time

6. I will also have to switch out the feature control frames (there will be 2 choices) - names to be determined.

 

 

Thank you

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 13047 StartFragment: 314 EndFragment: 13015 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

DimStyle = DIM_STYLE
'----------------------- Looks at Each Sheet ------------------------
For Each oSheet In oDrawDoc.Sheets 
    '----------------------Reference to the style manager -----------
    Dim oStylesMgr As DrawingStylesManager = oDoc.StylesManager

    '---- Get the reference to the target dimension style (by name)---
    Dim oDimStyle As DimensionStyle 
    Dim oOrdDimStyle As DimensionStyle
    If DimStyle = "ANSI - MM" Then
        oDimStyle = oStylesMgr.DimensionStyles.Item("ANSI - MM")
        oOrdDimStyle = oStylesMgr.DimensionStyles.Item("ANSI - ORDINATE - MM")
    Else
        oDimStyle = oStylesMgr.DimensionStyles.Item("ANSI - INCH [MM]")
        oOrdDimStyle = oStylesMgr.DimensionStyles.Item("ANSI - ORDINATE - INCH [MM]")
    End If

    '--------------------General Set Up ------------------------------
    Dim oDims As DrawingDimensions = oSheet.DrawingDimensions    
    Dim oGenDim As GeneralDimension    
    Dim oOrdDim As OrdinateDimension  
    
    '--------------------Changes General Dimensions--------------------
        For Each oGenDim  In oDims.GeneralDimensions             
        oGenDim.Style = oDimStyle
    Next
    
    '--------------------Changes Ordinate Dimensions-------------------
    For Each oOrdDim  In oDims.OrdinateDimensions             
        oOrdDim.Style = oOrdDimStyle
    Next

    '--------------------Changes Hole & Thread Dimensions--------------
    Dim oThreadNote As HoleThreadNote
    For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes
        oThreadNote.Style = oDimStyle
    Next

Next

 

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

Anonymous
Not applicable

I looked at my code last night and I came to the conclusion I didn't have my head on right when I attempted this the first time.

 

I almost  have it working now.

 

The only two issue I am having now is:

 

1. changing the dimension style to Inch Doesn't work, kicks up an error and I do not know why.

2. The feature control frame style change is not working. It is a minor error I can't figure out.

 

These are very minor issues and any solutions would be appreciated.

 

I have attached the drawing where all the code is located and an associated test part to verify the program. 

 

I am using the 2017 version of Inventor.

 

 

The code can be found in the rule "DIMENSION AND TEXT STYLE" or you can run it from the local form. These rules will be external eventually, as I am just testing them out. For those not using Inventor 2017 I have included the code below.

 

 

SyntaxEditor Code Snippet

'---------------------START OF iLogic
Dim Message As Integer
Dim N As Integer'---------------------TOTAL NUMBER OF SHEETS

'---------------------PARAMETER CHECK
Try
oTest = Parameter("DIM_STYLE")
Catch
'---------------------MULTI-VALUE TEXT PARAMETER CREATION
ThisDoc.Document.Parameters.UserParameters.AddByValue("DIM_STYLE", "METRIC", UnitsTypeEnum.kTextUnits)
'---------------------SET LIST
MultiValue.SetList("DIM_STYLE", "METRIC", "INCH")
End Try
Parameter.Param("DIM_STYLE").IsKey = True

'---------------THIS SECTION COUNTS THE TOTAL NUMBER OF SHEETS
Dim oDrawing As DrawingDocument
oDrawing = ThisApplication.ActiveDocument
Dim osheet As Sheet
i = 0
'---------------------COUNT TOTAL NUMBER OF SHEETS
For Each osheet In oDrawing.Sheets
If osheet.ExcludeFromCount = True Then
i = i + 1
Else
End If
Next
'---------------------REMOVE THE EXCLUDED SHEET FROM THE TOTAL NUMBER OF SHEETS
oMySheetCount = oDrawing.Sheets.Count - i
N = oMySheetCount

'---------------------------------------Message Box asking the user if they wish to continue---------------------------------
Message = MessageBox.Show("This operation will change all Dimensions " & N & " Sheets. Press the OK button, if you wish to continue.", "Drawing Style Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
If Message = 2 Then 
Exit Sub
Else


'---------------THIS SECTION CHANGES THE DRAWING STYLE'---------------------PICK DRAWING UNITS
DIM_STYLE= InputListBox("SELECT THE DESIRED DRAWING UNITS", MultiValue.List("DIM_STYLE"), DIM_STYLE, Title := "DRAWING UNITS", ListName := "DWG UNITS SELECTIONS")
InventorVb.DocumentUpdate()

'---------------------SECTION TO CHANGE ALL DIMENSIONS FEATURE CONTROL FRAMES TO THE CORRECT STYLES

'---------------------DEFINE THE DRAWING DOCUMENT
Dim oDrawDoc As DrawingDocument = ThisDoc.Document
'---------------------LOOK AT EACH SHEET
For Each oSheet In oDrawDoc.Sheets
'---------------------REFERENCE TO THE STYLE MANAGER
    Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager
'---------------------GET THE REFERENCE TO THE TARGET DIMENSION STYLE (BY NAME)
    Dim oDimStyle As DimensionStyle
    Dim oDimStyle2 As DimensionStyle
'    Dim oFCFStyle As FeatureControlFrameStyle
    DimStyle = DIM_STYLE
    If DimStyle = "METRIC" Then
        oDimStyle = oStylesMgr.DimensionStyles.Item("ANSI - MM")
        oDimStyle2 = oStylesMgr.DimensionStyles.Item("ANSI - ORDINATE - MM")
'        oFCFStyle = oStylesMgr.FeatureControlFrameStyles.Item("ANSI - FCF - MM")
        oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles.Item("ANSI - FSE - MM")
    ElseIf DimStyle = "INCH" Then
        oDimStyle = oStylesMgr.DimensionStyles.Item("ANSI - INCH")
        oDimStyle2 = oStylesMgr.DimensionStyles.Item("ANSI - ORDINATE - IN [MM]")
'        oFCFStyle = oStylesMgr.FeatureControlFrameStyles.Item("ANSI - FCF - INCH")
        oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles.Item("ANSI - FSE - INCH")
    End If
'---------------------DECLARING THE VARIABLES
    Dim oDims As DrawingDimensions = oSheet.DrawingDimensions    
    Dim oGenDim As GeneralDimension    
    Dim oOrdDim As OrdinateDimension 
'    Dim oFCF As FeatureControlFrame'---------------------CHANGE THE GENERAL DIMENSIONS
    For Each oGenDim  In oDims.GeneralDimensions             
        oGenDim.Style = oDimStyle
    Next   
'---------------------CHANGE THE ORDINATE DIMENSIONS
    For Each oOrdDim  In oDims.OrdinateDimensions             
        oOrdDim.Style = oDimStyle2
    Next
'---------------------CHANGE THE FEATURE CONTROL FRAMES'    For Each oFCF  In oFCF.FeatureControlFrames             '        oFCF.Style = oFCFStyle'    Next'---------------------CHANGE THE HOLE & THREAD SIZE
    Dim oThreadNote As HoleThreadNote
    For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes
    oThreadNote.Style = oDimStyle
    Next
Next

End If

'---------------------ACTIVATE SHEET 1
ActiveSheet = ThisDrawing.Sheet("Sheet:1")
'---------------------ZOOM ALL
ThisApplication.ActiveView.Fit
iLogicVb.UpdateWhenDone = True
RuleParametersOutput()    
InventorVb.DocumentUpdate()
ThisDoc.Save

'-------------------END OF iLogic-------------------------------








 

 

0 Likes
Message 3 of 5

Anonymous
Not applicable
Accepted solution
I figured out the issue with changing to inch dimensions. My Inch styles had an extra space in the name.

I still can't figure out the FCF issue.
0 Likes
Message 4 of 5

adam.nagy
Autodesk Support
Autodesk Support

Hi Jason,

 

What is exactly the FCF issue?

You change the style for them programmatically and nothing visibly changes? 

What happens if you change the style in the UI?

What happens if you reopen the drawing after changing the style? Still not good?

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

Adam,

 

    The issue I was having was trying to grab the FCF  to change the styles. I wasn't able to for some time, but I figured out what was going on and was able to select and change the FCS style.

 

The reason for wanting to change the styles is when we have an Inch Drawing for the tolerance value in the FCS we want the following:

 

- No Leading Zeros and trailing zeros.

 

When we have a Metric drawing we want:

 

- leading zeros and no trailing zeros

 

The industry standards require this.

 

What I found in my code was a minor typo in one of the lines and I had a line of code not needed that was causing the issue.

 

Here is the code I have to change everything I was wanting to do and it works.

 

Thank you for your reply.

 

'---------------------START OF iLogic

Dim Message As Integer

Dim N As Integer'---------------------TOTAL NUMBER OF SHEETS

 

'---------------------PARAMETER CHECK

Try

oTest = Parameter("DIM_STYLE")

Catch

'---------------------MULTI-VALUE TEXT PARAMETER CREATION

ThisDoc.Document.Parameters.UserParameters.AddByValue("DIM_STYLE", "METRIC", UnitsTypeEnum.kTextUnits)

'---------------------SET LIST

MultiValue.SetList("DIM_STYLE", "METRIC", "INCH")

End Try

Parameter.Param("DIM_STYLE").IsKey = True

 

'---------------THIS SECTION COUNTS THE TOTAL NUMBER OF SHEETS

Dim oDrawing As DrawingDocument

oDrawing = ThisApplication.ActiveDocument

Dim osheet As Sheet

i = 0

'---------------------COUNT TOTAL NUMBER OF SHEETS

For Each osheet In oDrawing.Sheets

If osheet.ExcludeFromCount = True Then

i = i + 1

Else

End If

Next

'---------------------REMOVE THE EXCLUDED SHEET FROM THE TOTAL NUMBER OF SHEETS

oMySheetCount = oDrawing.Sheets.Count - i

N = oMySheetCount

 

'---------------------------------------Message Box asking the user if they wish to continue---------------------------------

Message = MessageBox.Show("This operation will change all Dimensions on " & N & " Sheets. Press the OK button, if you wish to continue.", "Drawing Style Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)

If Message = 2 Then

Exit Sub

Else

 

 

'---------------THIS SECTION CHANGES THE DRAWING STYLE

'---------------------PICK DRAWING UNITS

DIM_STYLE= InputListBox("SELECT THE DESIRED DRAWING UNITS", MultiValue.List("DIM_STYLE"), DIM_STYLE, Title := "DRAWING UNITS", ListName := "DWG UNITS SELECTIONS")

InventorVb.DocumentUpdate()

 

'---------------------SECTION TO CHANGE ALL DIMENSIONS FEATURE CONTROL FRAMES TO THE CORRECT STYLES

 

'---------------------DEFINE THE DRAWING DOCUMENT

Dim oDrawDoc As DrawingDocument = ThisDoc.Document

'---------------------LOOK AT EACH SHEET

For Each oSheet In oDrawDoc.Sheets

'---------------------REFERENCE TO THE STYLE MANAGER

    Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager

'---------------------GET THE REFERENCE TO THE TARGET DIMENSION STYLE (BY NAME)

    Dim oDimStyle As DimensionStyle

    Dim oDimStyle2 As DimensionStyle

    DimStyle = DIM_STYLE

    If DimStyle = "INCH" Then

        oDimStyle = oStylesMgr.DimensionStyles.Item("ANSI - IN [MM]")

        oDimStyle2 = oStylesMgr.DimensionStyles.Item("ANSI - ORDINATE - IN [MM]")

        oFCFStyle = oStylesMgr.FeatureControlFrameStyles.Item("ANSI - FCF - INCH")

        oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles.Item("ANSI - FSE - INCH")

    ElseIf DimStyle = "METRIC" Then

        oDimStyle = oStylesMgr.DimensionStyles.Item("ANSI - MM")

        oDimStyle2 = oStylesMgr.DimensionStyles.Item("ANSI - ORDINATE - MM")

        oFCFStyle = oStylesMgr.FeatureControlFrameStyles.Item("ANSI - FCF - MM")

        oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles.Item("ANSI - FSE - MM")

    End If

'---------------------DECLARING THE VARIABLES

    Dim oDims As DrawingDimensions = oSheet.DrawingDimensions   

    Dim oGenDim As GeneralDimension   

    Dim oOrdDim As OrdinateDimension

    Dim oFCF As FeatureControlFrame

'---------------------CHANGE THE GENERAL DIMENSIONS

    For Each oGenDim  In oDims.GeneralDimensions            

        oGenDim.Style = oDimStyle

    Next  

'---------------------CHANGE THE ORDINATE DIMENSIONS

    For Each oOrdDim  In oDims.OrdinateDimensions            

        oOrdDim.Style = oDimStyle2

    Next

'---------------------CHANGE THE FEATURE CONTROL FRAMES

    For Each oFCF In oSheet.FeatureControlFrames

        oFCF.Style = oFCFStyle

    Next

'---------------------CHANGE THE HOLE & THREAD SIZE

    Dim oThreadNote As HoleThreadNote

    For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes

        oThreadNote.Style = oDimStyle

    Next

Next

 

End If

 

'---------------------ACTIVATE SHEET 1

ActiveSheet = ThisDrawing.Sheet("Sheet:1")

'---------------------ZOOM ALL

ThisApplication.ActiveView.Fit

iLogicVb.UpdateWhenDone = True

RuleParametersOutput()   

InventorVb.DocumentUpdate()

ThisDoc.Save

 

'-------------------END OF iLogic-------------------------------

 

0 Likes