Using iLogic to change dimension styles on drawing: Round 2

Using iLogic to change dimension styles on drawing: Round 2

josephcooley
Advocate Advocate
3,023 Views
13 Replies
Message 1 of 14

Using iLogic to change dimension styles on drawing: Round 2

josephcooley
Advocate
Advocate

In reference to this topic.

http://forums.autodesk.com/t5/inventor-customization/using-ilogic-to-change-dimension-styles-on-draw...

 

I have been using this for a little bit and I've come across a little issue.  When I change from a metric to an imperial border it doesnt change what the new dimensions are when placed.  

 

There is also an issue of having two different styles of dimension 

 

I have another dimension style that I Use for elevations called "Elevations (US)" and "Elevations (metric)" When i put those styles on a drawing the rule threw this error:

 

Error in rule: Template Selection, in document: StormKing General Arrangement.dwg

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.GeneralDimension'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{EE21CD75-39FD-4683-BE24-BFBB9CA66EB4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

The info tab is this:

 

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.GeneralDimension'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{EE21CD75-39FD-4683-BE24-BFBB9CA66EB4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

I have confirmed that if I take the different dimension style off of the drawing it stop having the error.  Like the regular dimension styles there is a us and metric version so those need to be switched when the units are switched also.  A single drawing can have both styles.  Do you have any suggestions on how to fix this?

0 Likes
3,024 Views
13 Replies
Replies (13)
Message 2 of 14

xiaodong_liang
Autodesk Support
Autodesk Support
Hi josephcooley,

I took at a look at the drawing and iLogic rule in the other post, sorry, however I am struggling to understand how to test this problem. Could you provide a sample idw with the iLogic rule? Thank you.
0 Likes
Message 3 of 14

josephcooley
Advocate
Advocate

Here is the drawing template I'm working on.  There is a dimension styles in there called Elevation (Metric) and Elevation (US) that if you put a part on the sheet and add ordinate dimensions it will give the error.  The Elevation Dimensions make it in the format of "EL. XXXX ft." or "EL. XXXX mm" Im trying to figure out how to stop that error from popping up I need to be able to have both regular dimensions and Elevation dimensions on the sheet.

0 Likes
Message 4 of 14

xiaodong_liang
Autodesk Support
Autodesk Support
Hi josephcooley,

Sorry for late response.

I opened this drawing in Inventor. It looks there is not any iLogic rule. Can I understand the error can reproduce by UI operation as you described?

I can only find 'Elevation (Hydro Metric)' and 'Elevation (Hydro US)' in dimension style list. In addition ordinate dimension style of default style in this drawing is 'Default (ANSI)', instead of Elevation XXX. I also tried to add an ordinate dimension, but no error appeared.

Could you elaborate the steps? Thank you.
0 Likes
Message 5 of 14

MechMachineMan
Advisor
Advisor

In order to change what the dimensions are placed as, you need to change the style of the Object Defaults so that it chooses that new dimension style to place.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 6 of 14

josephcooley
Advocate
Advocate

Here is a test part with the drawing error that will pop up when the rule is run.  Let me know if you have any questions sorry about includign the wrong template this one definitely has the code in it though.

0 Likes
Message 7 of 14

xiaodong_liang
Autodesk Support
Autodesk Support

 

 

Hi josephcooley,

I opened the two files at my side. It looks they still have no iLogic rule with it. These are snapshots. Anything I am still missing?

In addition, it took quite a lot of time to open .dwg, partially maybe because of the file contains many hatches.

0 Likes
Message 8 of 14

josephcooley
Advocate
Advocate

That is bizzare I have no idea why no ilogic is showing up in your file.  I just redownloaded the file above and it looks like the attached screen shot.  Is there any reason that your inventor would be stripping the iLogic and the border? 

 

0 Likes
Message 9 of 14

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

I am using Inventor 2016. Which release you are using?

 

maybe you could copy the iLogic code here directly, rhough it might miss the context of the problem, but I can try if I can reproduce the problem by copying the codes to the document directly.

0 Likes
Message 10 of 14

josephcooley
Advocate
Advocate

Im using Inventor 2016 as well.  Try this one I didnt include the part but you'll need to put something on there and use one of the Elevation dimension styles for the error to pop up.  Let me know if there is still no Ilogic.  I checked this file and it does have the correct iLogic in it. 

 

In case it doesnt here is the iLogic

 

TitleBlock = InputListBox("Please select a the desired title block.", MultiValue.List("TitleBlock"), TitleBlock, Title := "Title Block Selection", ListName := "Options")
oDoc = ThisDoc.Document
oSheets = oDoc.Sheets

    For Each oSheet In oSheets
        oSheet.activate
        Select Case TitleBlock
            Case "Hillsboro"
                ActiveSheet.ChangeSize("B", MoveBorderItems := True)
                ActiveSheet.TitleBlock = "Hillsboro"
                DimStyle = "ANSI"
            Case "Maine"
                ActiveSheet.ChangeSize("B", MoveBorderItems := True)
                ActiveSheet.TitleBlock = "Maine"
                DimStyle = "ANSI"
            Case "Ely"
                ActiveSheet.ChangeSize("A3", MoveBorderItems := True)
                ActiveSheet.TitleBlock = "Ely"
                DimStyle = "ISO"
            Case "Clevedon"
                ActiveSheet.ChangeSize("A3", MoveBorderItems := True)
                ActiveSheet.TitleBlock = "Clevedon"
                DimStyle = "ISO"
            Case "HRD"
                ActiveSheet.ChangeSize("A3", MoveBorderItems := True)
                ActiveSheet.TitleBlock = "HRD"
                DimStyle = "ISO"
        End Select
    
    Next
oSheets(1).activate

'look at each sheet
For Each oSheet In oDoc.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 
    
    If DimStyle = "ANSI" Then
        oDimStyle = oStylesMgr.DimensionStyles.Item("Dimensions (Hydro US)")
        oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles _ 
            .Item("Hydro (US)") 
    Else
        oDimStyle = oStylesMgr.DimensionStyles.Item("Dimensions (Hydro Metric)")
        oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles _ 
            .Item("Hydro (Metric)") 
    End If
    
    'change general dimensions
    Dim oDims As DrawingDimensions = oSheet.DrawingDimensions
    For Each oDim As GeneralDimension In oDims
        oDim.Style = oDimStyle
    Next
    
    'change Hole and Thread Notes
    Dim oThreadNote As HoleThreadNote
    For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes
        oThreadNote.Style = oDimStyle
    Next
Next 'sheet 
0 Likes
Message 11 of 14

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

When I tried to test you iLogic code on the other machine, it is interesting that I can open your drawing with iLogic code. And it is surprise there is not many hatches this time…

 

Although I did not figure out why there is difference on my two machines, I can produce your problem now.

 

It failed at

'change general dimensions

    Dim oDims As DrawingDimensions = oSheet.DrawingDimensions

    For Each oDim As GeneralDimension In oDims

        oDim.Style = oDimStyle

 Next

 

If you check with other debugging tool such as VBA or VB.NET, you can find the dimensions in your sheet is NOT GeneralDimension. They are OrdinateDimension     . that is why the code failed to cast the OrdinateDimension type to GeneralDimension.

 

I made some adjustment as below. Now it works. Hope it helps.

 

 

 

TitleBlock = InputListBox("Please select a the desired title block.", MultiValue.List("TitleBlock"), TitleBlock, Title := "Title Block Selection", ListName := "Options")

oDoc = ThisDoc.Document

oSheets = oDoc.Sheets

 

    For Each oSheet In oSheets

        oSheet.activate

        Select Case TitleBlock

            Case "Hillsboro"

                ActiveSheet.ChangeSize("B", MoveBorderItems := True)

                ActiveSheet.TitleBlock = "Hillsboro"

                DimStyle = "ANSI"

            Case "Maine"

                ActiveSheet.ChangeSize("B", MoveBorderItems := True)

                ActiveSheet.TitleBlock = "Maine"

                DimStyle = "ANSI"

            Case "Ely"

                ActiveSheet.ChangeSize("A3", MoveBorderItems := True)

                ActiveSheet.TitleBlock = "Ely"

                DimStyle = "ISO"

            Case "Clevedon"

                ActiveSheet.ChangeSize("A3", MoveBorderItems := True)

                ActiveSheet.TitleBlock = "Clevedon"

                DimStyle = "ISO"

            Case "HRD"

                ActiveSheet.ChangeSize("A3", MoveBorderItems := True)

                ActiveSheet.TitleBlock = "HRD"

                DimStyle = "ISO"

        End Select

   

    Next

oSheets(1).activate

 

'look at each sheet

For Each oSheet In oDoc.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

   

    If DimStyle = "ANSI" Then

        oDimStyle = oStylesMgr.DimensionStyles.Item("Dimensions (Hydro US)")

        oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles _

            .Item("Hydro (US)")

    Else

        oDimStyle = oStylesMgr.DimensionStyles.Item("Dimensions (Hydro Metric)")

        oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles _

            .Item("Hydro (Metric)")

    End If

   

    'change general dimensions

    Dim oDims As DrawingDimensions = oSheet.DrawingDimensions   

   

    Dim oGenDim As GeneralDimension   

    Dim oOrdDim As OrdinateDimension    

   

    For Each oGenDim  In oDims.GeneralDimensions            

        oGenDim.Style = oDimStyle

    Next

   

    For Each oOrdDim  In oDims.OrdinateDimensions            

        oOrdDim.Style = oDimStyle

    Next

   

    'change Hole and Thread Notes

    Dim oThreadNote As HoleThreadNote

    For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes

        oThreadNote.Style = oDimStyle

    Next

Next 'sheet

 

Message 12 of 14

fce
Enthusiast
Enthusiast

Hello everyone,

 

 

I´m trying to implement a very similar iLogic rule in order to change the text height of the dimensions depending on the paper size.

Not only for already existing dimensions but also future ones.

 

I understand that the following code changes the complete 'Style and Standard' for the document/page:

 

oStylesMgr.ActiveStandardStyle = oStylesMgr.StandardStyles.Item("Test")

 

Being the new complete 'Style and Standard' = "Test".

 

The code is working perfectly but instead of changing the complete 'Style and Standard' is it possible to only change the dimension standard?

 

 

Best Regards,

Francisco Vaz 

 

0 Likes
Message 13 of 14

Anonymous
Not applicable

I have iLogic rule that changes all dimensions, Balloons, etc.

Problem is i cannot find how to access the Datum Target Style.

0 Likes
Message 14 of 14

xiaodong_liang
Autodesk Support
Autodesk Support

I would think this will need to turn to Inventor API, while I am not sure if such API is available. I will check and get back to you.

0 Likes