iLogic Sheet Size as External Rule

iLogic Sheet Size as External Rule

Jesper_S
Collaborator Collaborator
4,147 Views
14 Replies
Message 1 of 15

iLogic Sheet Size as External Rule

Jesper_S
Collaborator
Collaborator

Hi.

 

Got a Code to change the drawing sheetsize and bordertype.

Planning to run it as an external rule but cant get it to work.

Dim oDoc As Document
oDoc = ThisDoc.Document
Dim Doctype As String = "Drawing"
'doc = ThisApplication.ActiveDocument
'check file type
  If oDoc.DocumentType = kDrawingDocumentObject Then

    Dim selectedSize As String = "Sheet"
    Dim sizeList As New ArrayList
    sizeList.Add("A1")
    sizeList.Add("A2")
    sizeList.Add("A3")
    sizeList.Add("A4")
    
    'Display input list box and select size
    selectedSize = InputListBox("Select Size", sizeList, selectedSize, Title := "Change size",ListName := "Size")
	
	If selectedSize = "A1" Then
        ActiveSheet.ChangeSize("A1", MoveBorderItems := True)
        ThisApplication.ActiveDocument.ActiveSheet.Orientation  = kLandscapePageOrientation
        ActiveSheet.Border = "A1"
	End If	
	
	Else
	
	MessageBox.Show("This rule can only be run in a " & DocType & " file", "iLogic")
	Return
	End If

The two rows in Red seems to be the problem. If I comment them out it works and i get my Messagebox.

 

Thanks in advance.

 

//Jesper


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Accepted solutions (1)
4,148 Views
14 Replies
Replies (14)
Message 2 of 15

LishuangLu
Autodesk
Autodesk

Hi Jesper,

 

The code can be run in my side by changing to an existing border name in the drawing file.

ActiveSheet.Border = "A1"

 

Thanks,

-Lisa

0 Likes
Message 3 of 15

MechMachineMan
Advisor
Advisor

Here a transition to using the API instead of iLogic will help.

 

See enums:

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-55595BC5-77E1-485D-861D-B1FE827EE132

 

Dim oDoc As Document
oDoc = ThisDoc.Document
Dim Doctype As String = "Drawing"
  If oDoc.DocumentType = kDrawingDocumentObject Then

    Dim selectedSize As String = "Sheet"
    Dim sizeList As New ArrayList
    sizeList.Add("A1")
    sizeList.Add("A2")
    sizeList.Add("A3")
    sizeList.Add("A4")
    
    'Display input list box and select size
    selectedSize = InputListBox("Select Size", sizeList, selectedSize, Title := "Change size",ListName := "Size")
	
	If selectedSize = "A1" Then
            oDoc.ActiveSheet.Size = DrawingSheetSizeEnum.kA1DrawingSheetSize
            oDoc.ActiveSheet.Orientation  = kLandscapePageOrientation
            oDoc.ActiveSheet.Border = "A1"
	End If	
	
	Else
	
	MessageBox.Show("This rule can only be run in a " & DocType & " file", "iLogic")
	Return
	End If

 

 

 

 

 


--------------------------------------
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 4 of 15

JaneFan
Autodesk
Autodesk

Hi Jesper, 

 

In iLogic, the const name for enumerator is not acceptable, please use its value instead. 

I am seeing the error happens at the line: 

ThisApplication.ActiveDocument.ActiveSheet.Orientation  = kLandscapePageOrientation

 

Please change it to: 

SyntaxEditor Code Snippet

ThisApplication.ActiveDocument.ActiveSheet.Orientation  = 10242

 

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 5 of 15

LishuangLu
Autodesk
Autodesk

Jane is correct, please follow her suggestion to run in iLogic. I've uncommented the Orientation setting line, thus the code can pass in my side.

 

Thanks,

-Lisa

0 Likes
Message 6 of 15

Jesper_S
Collaborator
Collaborator
Hi.

I kind of forgot one importent thing. Was in a hurry.
What i was trying to to is if the rule is run in an part or assembly, the rule will show me the messagebox and then exit.

Works fine in a drawing.

Sorry.

//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 7 of 15

JaneFan
Autodesk
Autodesk

Hi Jesper, 

 

Here is the thing: 

When you run the rule in part or assembly document, it jumps to the line of MessageBox.Show() directly because the DocumentType is not kDrawingDocumentObject. 

When you run the rule in drawing document, it run the codes under this judgement statement:

SyntaxEditor Code Snippet

If oDoc.DocumentType = kDrawingDocumentObject Then  

 So please change the line when you run the code in drawing document, it will work:

SyntaxEditor Code Snippet

ThisApplication.ActiveDocument.ActiveSheet.Orientation  = 10242 

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 8 of 15

JaneFan
Autodesk
Autodesk

Or to make the code look nicer, we can replace the line with the one like this: 

SyntaxEditor Code Snippet

ThisApplication.ActiveDocument.ActiveSheet.Orientation  = PageOrientationTypeEnum.kLandscapePageOrientation 

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 9 of 15

Jesper_S
Collaborator
Collaborator

Hi.

 

When i run the ilogic code in a Part, i get this message.

 

Skärmklipp.PNG

Still the same thing, if i comment out the red line it works.

 

Dim oDoc As Document
oDoc = ThisDoc.Document
Dim Doctype As String = "Drawing"
'doc = ThisApplication.ActiveDocument
'check file type
  If oDoc.DocumentType = kDrawingDocumentObject Then

    Dim selectedSize As String = "Sheet"
    Dim sizeList As New ArrayList
    sizeList.Add("A1")
    sizeList.Add("A2")
    sizeList.Add("A3")
    sizeList.Add("A4")
    
    'Display input list box and select size
    selectedSize = InputListBox("Select Size", sizeList, selectedSize, Title := "Change size",ListName := "Size")
	
	If selectedSize = "A1" Then
        ActiveSheet.ChangeSize("A1", MoveBorderItems := True)
        ThisApplication.ActiveDocument.ActiveSheet.Orientation  = 10242
       ' ActiveSheet.Border = "A1"
	End If	
	
	Else
	
	MessageBox.Show("This rule can only be run in a " & DocType & " file", "iLogic")
	Return
	End If

//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 10 of 15

Jesper_S
Collaborator
Collaborator

Thanks @MechMachineMan.

Tried this code and it works as i want when i a Part or Assembly.

But got this when i run it in a Drawing.

Skärmklipp2.PNG

 

Something to do with this line.

 oDoc.ActiveSheet.Orientation  = kLandscapePageOrientation

if i comment it out ir works.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 11 of 15

MechMachineMan
Advisor
Advisor

As mentioned by an earlier commenter, it's because you need to put the enum type in before it.

 

Dim oDoc As Document
oDoc = ThisDoc.Document

  If oDoc.DocumentType = kDrawingDocumentObject Then

    Dim selectedSize As String = "Sheet"
    Dim sizeList As New ArrayList
    sizeList.Add("A1")
    sizeList.Add("A2")
    sizeList.Add("A3")
    sizeList.Add("A4")
    
    'Display input list box and select size
    selectedSize = InputListBox("Select Size", sizeList, selectedSize, Title := "Change size",ListName := "Size")
	
	If selectedSize = "A1" Then
		Try
			oDoc.ActiveSheet.Size = DrawingSheetSizeEnum.kA1DrawingSheetSize
		Catch
			MsgBox("Error Changing Sheet Size!")
		End Try
		
		'oDoc.ActiveSheet.Border.Delete
		'oDoc.ActiveSheet.TitleBlock.Delete
		Try
			oDoc.ActiveSheet.Orientation  = PageOrientationTypeEnum.kLandscapePageOrientation
		Catch
			MsgBox("Error Changing Sheet Orientation!")
		End Try
        
		Try
			oDoc.ActiveSheet.Border = "A1"
		Catch
			MsgBox("Error Changing Sheet Border!")
		End Try

	End If	
	
	Else
	
	MsgBox("This rule can only be run in a drawing file",, "iLogic")
	Return
End If

--------------------------------------
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 12 of 15

Jesper_S
Collaborator
Collaborator

Hi.

 

Missed that, works now.

But i still get an error on the border insert. 

Do i have to delete the existing border and then insert the new or is it something else?

Is there an Enum for border also?

 

//Jesper


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 13 of 15

MechMachineMan
Advisor
Advisor

If your border has prompted entries and you aren't supplying those, that could be an issue.

 

If your border is a different size than your sheet, that could be an issue.

 

And I do also think you do have to delete the old border before putting the new one in.

 

These are all things you can test simply - either by trying to perform the same thing with the UI (generally works), or by tweaking your code/test setup so you know that is the only thing that could be wrong.


--------------------------------------
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 14 of 15

Jesper_S
Collaborator
Collaborator

No promted entries. Same size. Same thing if i delete the border.

 

If I insert it manually it works. If I remove oDoc. infront of 

oDoc.ActiveSheet.Border = "A1"

 and run the rule in a drawing it works, but then it doesnt work when run in a part. 

Think i will skip having this as an external rule and just put the code in the template instead.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 15 of 15

Anonymous
Not applicable
Accepted solution

 

I found another thread https://forums.autodesk.com/t5/inventor-customization/ilogic-change-drawing-borders-from-assembly/td...

 

I declared the variables inside the i kdrawingDocumentObject if statement

 

    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
    'reference to the active sheet
    Dim oSheet As Sheet = oDrawDoc.ActiveSheet
    'delete current border on the active sheet
    Dim oBorder As Border = oSheet.Border

 

And the code for changing the border and sheetsize + orientation

 

 

            Try
                oBorder.Delete
                Dim oBorderDef As BorderDefinition = oDrawDoc.BorderDefinitions.Item("A1")
                oSheet.AddBorder(oBorderDef)
            Catch
                MsgBox("Error Changing Sheet Border!")
            End Try

 

The code now works both in a drawing and in all other filetypes displays "this is not a drawing" and exits

 

If this is horrible use and mix of code, vb, api etc i don't know. But it works 🙂

 

 

// Dupont