Using iLogic to Create New Sheet and place views

Using iLogic to Create New Sheet and place views

jfenter
Enthusiast Enthusiast
5,692 Views
14 Replies
Message 1 of 15

Using iLogic to Create New Sheet and place views

jfenter
Enthusiast
Enthusiast

I want to create an iLogic rule within an idw that will create a Sheet:2 and place a base view and projected view to scale on that new sheet.

 

The rule would be driven by a parameter in the ipt named "Part_Type".  When the designated part type is active, the rule in the idw would run and create the 2nd sheet, placing the views.  Ideally, I would also like to place some basic dimensions as well but I think that is too advanced for me at this point (especially given I can't even create the sheet:2 now).

 

I've searched through the forums and found some information, but my knowledge of the API is limited at best. 

 

Part type would be defined as parameter in the ipt.

User would start a new drawing sheet as usual from a template already created with title block, sheet size (C) and border information already defined in sheet:1.

The view style for both the base and projected view would include hidden lines.

The scale would need to be a factor of some value that can be calculated for different sized parts.

 

Any help would be appreciated. 

0 Likes
Accepted solutions (1)
5,693 Views
14 Replies
Replies (14)
Message 2 of 15

Sergio.D.Suárez
Mentor
Mentor

 

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.Sheets(1)
oSheet.Activate

Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 

' Get control definition for the line command. 
Dim oControlDef As ControlDefinition 
 oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingNewSheetCtxCmd")  
' Execute the command. 
Try
oControlDef.Execute
Dim oSheet2 As Sheet 
oSheet2 = ThisDoc.Document.ActiveSheet
oSheet2.Name ="Sheet:2"
oSheet2.ExcludeFromPrinting = False
oSheet2.ExcludeFromCount = False
Catch
End Try

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 15

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, Here is an example of a rule that inserts a new sheet, then select a view to insert and then retrieve dimensions and then center them.
You could automatically insert a specific view to fix it in a specific location, but for this purpose all views created with the same initial plane criteria should be included, since the view that would be placed would be "front" and all should be similar. Another situation would arise with the scale, would have to scale the piece automatically in a space of the given sheet. It seemed more correct to me simply to choose it to locate it as one wishes and then to recover automatically the dimensions with which it was created. I hope it is useful. regards

 

 

Sub main()
	 add_Sheet
	add_view
	End Sub
	
Sub add_Sheet
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.Sheets(1)
oSheet.Activate

Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 

' Get control definition for the line command. 
Dim oControlDef As ControlDefinition 
 oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingNewSheetCtxCmd")  
' Execute the command. 
Try
oControlDef.Execute
Dim oSheet2 As Sheet 
oSheet2 = ThisDoc.Document.ActiveSheet
oSheet2.Name ="Sheet"
oSheet2.ExcludeFromPrinting = False
oSheet2.ExcludeFromCount = False
oSheet2.Activate
Catch
End Try
End Sub

Sub add_view
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oView As DrawingView

Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 

' Get control definition for the line command. 
Dim oControlDef As ControlDefinition 
 oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingBaseViewCmd")  
 oControlDef.Execute2(True)
 
 'Retrieve Dimensions
For Each oView In oDoc.ActiveSheet.DrawingViews
	Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
	oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView)
 Next
 
 'Center Dimensions
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
        Call oDrawingDim.CenterText
    End If
Next
 End Sub

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 4 of 15

jfenter
Enthusiast
Enthusiast

That works almost exactly as I wanted!  Do you know if there is a way to only dimension certain dimensions?  When I run this rule, I get a lot of redundant dimensions.

0 Likes
Message 5 of 15

Sergio.D.Suárez
Mentor
Mentor

If I know, it was an idea that I once proposed in the forum, that you can select a dimension and mark it uncheck it for automatic recovery. I have not yet investigated if you can apply a rule for each type of dimension, any news will warn you


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 6 of 15

jfenter
Enthusiast
Enthusiast

One other question that might perfect this code for me.  Can something be added that this rule runs automatically based on a parameter in the ipt?  Only certain part types will require the additional 2D sheet and I would like to have the rule run based on the status of that Part_Type parameter in the model.

 

0 Likes
Message 7 of 15

jfenter
Enthusiast
Enthusiast

For some reason, it's bringing in 4 copies of each dimension.

 

dwg.PNG

Message 8 of 15

Sergio.D.Suárez
Mentor
Mentor

Hello, Excuse me for taking a long time to respond. Here you have a rule that I think does what you are looking for, First you must create a user parameter of the text type, you create multiple value. In my case, the status is "single" and "Sheet 2D". If it is placed on Sheet 2D, the new sheet and the view (s) will be created. You can add the event so that this rule is activated before saving the document. This rule is an animate example to modify and visualize changes. Greetings.

 

 

Sub Main ()
On Error Resume Next
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
SheetWidth=ActiveSheet.Width/10  'sheet units in cm
SheetHeight = ActiveSheet.Height/10 'sheet units in cm
oTG = ThisApplication.TransientGeometry
oPoint1 = oTG.CreatePoint2d(SheetWidth/2, SheetHeight/2)' view insert point

InventorVb.DocumentUpdate()
Dim oView As DrawingView 
 	oView = oDoc.Sheets.Item(1).DrawingViews.Item(1)'firstviewfirstsheet
	oViewScale = oView.Scale
	oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oParam As Parameter
	oParam=oViewModelDoc.ComponentDefinition.Parameters.Item("Part_Type")

	If oParam.Value = "Sheet 2D" Then
		add_Sheet
	
		oDoc.Sheets.Item(2).DrawingViews.AddBaseView(oViewModelDoc, oPoint1, oViewScale, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle, "Default")
																																							'kFromBaseDrawingViewStyle 32260 Derive the Style From the base drawing View. 
																																							'kHiddenLineDrawingViewStyle 32257 Hidden line style. 
																																							'kHiddenLineRemovedDrawingViewStyle 32258 Hidden lines removed style. 
																																							'kShadedDrawingViewStyle 32259 Shaded style (With hidden lines removed). 
																																							'kShadedHiddenLineDrawingViewStyle
	 	NewView = oDoc.Sheets.Item(2).DrawingViews.Item(1)
		Dim oCommand As CommandManager
		oCommand = ThisApplication.CommandManager
		oCommand.DoSelect(NewView)
		Dim oControlDef As ControlDefinition 
 		oControlDef = oCommand.ControlDefinitions.Item("DrawingViewEditCtxCmd")  
 		oControlDef.Execute2(True)
	
		Dim oNewView As DrawingView 
		For Each oNewView In oDoc.Sheets.Item(2).DrawingViews
			Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
			oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oNewView)
		 Next
		 'Center Dimensions
		Dim oDrawingDim As DrawingDimension
		' Iterate over all dimensions in the drawing and
		' center them if they are linear or angular.
		For Each oDrawingDim In oDoc.Sheets.Item(2).DrawingDimensions
		    If TypeOf oDrawingDim Is LinearGeneralDimension Or _
		       TypeOf oDrawingDim Is AngularGeneralDimension Then
		        Call oDrawingDim.CenterText
		    End If
		Next
	End If
End Sub
	
Sub add_Sheet
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheet As Sheet
oSheet = oDoc.Sheets(1)
oSheet.Activate

Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 
' Get control definition for the line command. 
Dim oControlDef As ControlDefinition 
 oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingNewSheetCtxCmd")  
' Execute the command. 
Try
oControlDef.Execute
Dim oSheet2 As Sheet 
oSheet2 = ThisDoc.Document.ActiveSheet
oSheet2.Name ="Sheet"
oSheet2.ExcludeFromPrinting = False
oSheet2.ExcludeFromCount = False
oSheet2.Activate
Catch
End Try
End Sub

Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 9 of 15

jfenter
Enthusiast
Enthusiast

That doesn't work quite the way I was hoping, but it does place the view and add dimensions.  I was hoping to have the Add Sheet rule run automatically after the part was placed on sheet 1.  The rule would then read the part type from the base view on sheet 1 and determine if sheet 2 was necessary based on the Part_type parameter.  Perhaps my desired result isn't possible with iLogic.  I certainly appreciate all your help with this.

0 Likes
Message 10 of 15

Sergio.D.Suárez
Mentor
Mentor

Here is another rule variation. When creating a new drawing file, you execute the rule and insert a view in the default sheet, if the parameter changes as in the previous examples, the sheet will be added and the default dimensions will be added


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 11 of 15

jfenter
Enthusiast
Enthusiast

That looks like it would work the way I'm hoping.  Is that activated by an Event Trigger?

0 Likes
Message 12 of 15

Sergio.D.Suárez
Mentor
Mentor

Do not.
Try adding event triggers but the rule did not complete the function, so I decided to look for another path, you can try it, where I failed, maybe you can succeed, if you discover the error you can share it so we learn both.


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 13 of 15

jfenter
Enthusiast
Enthusiast

what is the code for your last example?

0 Likes
Message 14 of 15

Sergio.D.Suárez
Mentor
Mentor

Oh! Excuse me, I thought I had sent it before, greetings!

 

Sub Main()
Try
	Dim oCommandMgr As CommandManager 
	oCommandMgr = ThisApplication.CommandManager 
	InventorVb.DocumentUpdate()
	Try
		check_view
	Catch
		Dim CreateBaseView As ControlDefinition 
		CreateBaseView = oCommandMgr.ControlDefinitions.Item("DrawingBaseViewCmd")  
		CreateBaseView.Execute2(True)
		check_view
	End Try
Catch
End Try
InventorVb.DocumentUpdate()
End Sub

Sub check_view
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
SheetWidth=ActiveSheet.Width/10  'sheet units in cm
SheetHeight = ActiveSheet.Height/10 'sheet units in cm
oTG = ThisApplication.TransientGeometry
oPoint1 = oTG.CreatePoint2d(SheetWidth / 2, SheetHeight / 2)' view insert point
Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 
InventorVb.DocumentUpdate()
	Dim oView As DrawingView 
 	oView = oSheet.DrawingViews.Item(1)'firstviewfirstsheet
	oViewScale = oView.Scale
	oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oParam As Parameter
	oParam=oViewModelDoc.ComponentDefinition.Parameters.Item("Part_Type")
	If oParam.Value = "Sheet 2D" Then	
		Dim oControlDef As ControlDefinition 
		 oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingNewSheetCtxCmd")  
		' Execute the command. 
		Try
		oControlDef.Execute
		Dim oSheet2 As Sheet 
		oSheet2 = oDoc.ActiveSheet
		oSheet2.Name ="Sheet"
		oSheet2.ExcludeFromPrinting = False
		oSheet2.ExcludeFromCount = False
		oSheet2.Activate
		Catch
		End Try
		oDoc.Sheets.Item(2).DrawingViews.AddBaseView(oViewModelDoc, oPoint1, oViewScale, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle, "Default")
																																							'kFromBaseDrawingViewStyle 32260 Derive the Style From the base drawing View. 
																																							'kHiddenLineDrawingViewStyle 32257 Hidden line style. 
																																							'kHiddenLineRemovedDrawingViewStyle 32258 Hidden lines removed style. 
																																							'kShadedDrawingViewStyle 32259 Shaded style (With hidden lines removed).																																					'kShadedHiddenLineDrawingViewStyle
	 	NewView = oDoc.Sheets.Item(2).DrawingViews.Item(1)
		oCommandMgr.DoSelect(NewView)
		Dim oControlDef2 As ControlDefinition 
 		oControlDef2 = oCommandMgr.ControlDefinitions.Item("DrawingViewEditCtxCmd")  
 		oControlDef2.Execute2(True)
	
		Dim oNewView As DrawingView 
		For Each oNewView In oDoc.Sheets.Item(2).DrawingViews
			Dim oGeneralDimensionsEnum As GeneralDimensionsEnumerator
			oGeneralDimensionsEnum = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oNewView)
		 Next
		 'Center Dimensions
		Dim oDrawingDim As DrawingDimension
		' Iterate over all dimensions in the drawing and
		' center them if they are linear or angular.
		For Each oDrawingDim In oDoc.Sheets.Item(2).DrawingDimensions
		    If TypeOf oDrawingDim Is LinearGeneralDimension Or _
		       TypeOf oDrawingDim Is AngularGeneralDimension Then
		        Call oDrawingDim.CenterText
		    End If
		Next
	End If
	
End Sub

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 15 of 15

ria.markides
Observer
Observer

Hi, the information on this thread is very useful. Any updates on the topic of only displaying certain dimensions? 

Thanks

0 Likes