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: 

iLogic Errors for Center/Arrange Dimensions on All Sheets

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
624 Views, 3 Replies

iLogic Errors for Center/Arrange Dimensions on All Sheets

Hello Everyone,

 

I am running into an issue with some code and I am hoping someone here can help me.  I am trying to create an iLogic rule (see bottom of this post) that will center and arrange dimensions on all sheets of a drawing.  While rummaging through this forum, I have found some code that does the trick.  (It's a bit of a Frankenstein's monster of two different code I found.)  Once I confirmed that this works in the current drawing, I copy and paste the rule in another drawing and try to run it.  Sometimes, the code will run fine in the new document.  most of the time, I get the following error.

 

Error Message Tab

Error in rule: Rule2, in document: DSFAB-XXX-001.idw

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

More Info Tab

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.DrawingDimensions.Arrange(ObjectCollection DrawingDimensions, Object ContourEntity)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

I'm sure there is something wrong with my rule.  It's a merger of a "center dims" and "arrange dims" rule.  If any of you have a few moments to look through this and show me where I went wrong, I would be very grateful.

 

iLogic Code

Dim doc As Inventor.DrawingDocument = ThisDoc.Document
For Each sheet As Sheet In doc.Sheets
'sheet.Activate
Dim dimensions As Inventor.ObjectCollection = ThisServer.TransientObjects.CreateObjectCollection
Dim drawDim As Inventor.DrawingDimension
  For Each drawDim In sheet.DrawingDimensions
    If Not TypeOf drawDim Is Inventor.OrdinateDimensionSet _
      And Not TypeOf drawDim Is Inventor.BaselineDimensionSet _
      And Not TypeOf drawDim Is Inventor.ChainDimensionSet Then
     dimensions.Add(drawDim)
    End If
  Next
  sheet.DrawingDimensions.Arrange(dimensions)
Next


'Set a reference To the active drawing document
    
    Dim odoc As Document
    odoc = ThisApplication.ActiveDocument
' Set a reference to the active sheet
    Dim oSheet As Sheet
     
    For Each oSheet In oDoc.Sheets
    Dim oDrawingDim As DrawingDimension
' Iterate over all dimensions in the drawing and
    ' center them if they are linear or angular.
For Each oDrawingDim In oSheet.DrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or _
           TypeOf oDrawingDim Is AngularGeneralDimension Then
             oDrawingDim.CenterText
        End If
    Next
    Next

 

I am running Inventor 2016

3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

This is the code I am currently running to arrange all dimensions. Hope it helps in some small way.

 

SyntaxEditor Code Snippet

'define application
Dim oApp As Application
oApp = ThisApplication
'define active doc
Dim oDoc As DrawingDocument
oDoc = oApp.ActiveDocument
'get dims
Dim oDims As DrawingDimensions
oDims = oDoc.ActiveSheet.DrawingDimensions
'create dim collection
Dim oDimCol As ObjectCollection
oDimCol = oApp.TransientObjects.CreateObjectCollection

'step through all dims one at a time
Dim oDim As DrawingDimension
For Each oDim In oDims
    If TypeOf oDim Is LinearGeneralDimension _
	Or TypeOf oDim Is AngularGeneralDimension Then
       oDim.CenterText 'center the dim
       oDimCol.Add(oDim) 'add the dim to collection
    End If
Next
'arrange the collection of dims
oDims.Arrange(oDimCol)
Message 3 of 4
Anonymous
in reply to: Anonymous

Thank you.  Your rule is much cleaner and easier to understand than mine is.  Any idea if it is possible to make this work on all sheets in a drawing at once?  I think I have zeroed in on the code that will do this but, I can't seem to stick it where it needs to go to work without getting the error above.

 

For Each oSheet In oDoc.Sheets

'ENTER RULES HERE

Next
Message 4 of 4
PCP7
in reply to: Anonymous

How do I make the same rule work for selected few sheets ?

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report