Run rule in drawing from assembly won't work silently

Run rule in drawing from assembly won't work silently

snichols
Advocate Advocate
386 Views
2 Replies
Message 1 of 3

Run rule in drawing from assembly won't work silently

snichols
Advocate
Advocate

Hello all, I have a rule in an assembly that runs a rule in a drawing that positions and scales the view on the sheet. If I run the rule from the assembly silently it throws an error. If I don't run it silently it works just fine. I was wondering if there was some way to run it silent and it work. The rules are below. Thanks in advance for any help!

 

'This is from the rule in the assembly document
'
open drawing document DwgFilename = ThisDoc.Path & "\Dwgs\MyDwg.dwg"
'It works if I run the rule this way Dim oDrawDoc as DrawingDocument = ThisApplication.Documents.Open(Dwgfilename)
'It does NOT work if I run the rule this way 'Dim oDrawDoc as DrawingDocument = ThisApplication.Documents.Open(Dwgfilename, False) 'run rule in the drawing document auto = iLogicVb.Automation auto.RunRule(oDrawDoc, "POSITION VIEW") oDrawDoc.Save oDrawDoc.Close

'This is the "POSITION VIEW" rule in the drawing
Dim
oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet = oDrawDoc.ActiveSheet Dim oViews As DrawingViews = oSheet.DrawingViews Dim oView As DrawingView = oSheet.DrawingViews(1) 'Adjust VIEW 1 SCALE until it fits the sheet height'ActiveSheet = oDrawDoc.Sheet("Layout1:1") STARTSCALE = 0.125 oView.Scale = STARTSCALE InventorVb.DocumentUpdate() TryAgain: InventorVb.DocumentUpdate() SheetHeight = oSheet.Height - 0 ViewHeight = oView.Height ScaleStep = 0.02 If ViewHeight > SheetHeight Then VIEWSCALE = STARTSCALE - ScaleStep STARTSCALE = VIEWSCALE RuleParametersOutput() oView.Scale = VIEWSCALE InventorVb.DocumentUpdate() ActiveSheet.View(1).SetSpacingToCorner(1, 2.25, SheetCorner.BottomLeft) InventorVb.DocumentUpdate() If VIEWSCALE <= 0.01 Then MessageBox.Show("That's too darn small!", "ilogic") Return 'exit rule Else Goto TryAgain End If InventorVb.DocumentUpdate() End I 

 

0 Likes
387 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor

I'd try to change the line

oDrawDoc = ThisApplication.ActiveDocument

To

oDrawDoc = ThisDoc.Document

in the rule in your drawing. The drawing document isn't the active document when not visible 🙂

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Another option:

I almost always use "ThisDrawing.Document" when dealing with a DrawingDocument.

Example:

Dim oDDoc As DrawingDocument = ThisDrawing.Document

It should work for your situation too.

It "Gets the drawing document in which the rule is running."

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes