Create centerline on a plate with iLogic

Create centerline on a plate with iLogic

sbcJLYKK
Contributor Contributor
1,326 Views
7 Replies
Message 1 of 8

Create centerline on a plate with iLogic

sbcJLYKK
Contributor
Contributor

Hi

I hope you can help me.

 

 

I have this iLogic code

 

'Set a reference to the active drawing document

Dim oDoc As DrawingDocument

oDoc = ThisDoc.Document


Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

oSheets = oDoc.Sheets
oSheet = oDoc.ActiveSheet

For Each oSheet In oSheets
oViews = oSheet.DrawingViews

For Each oView In oViews
Dim oCenterline As AutomatedCenterlineSettings
oView.GetAutomatedCenterlineSettings(oCenterline)
oCenterline.ProjectionParallelAxis = True

oView.SetAutomatedCenterlineSettings(oCenterline)


Dim resultCenters As ObjectsEnumerator
resultCenters = oView.SetAutomatedCenterlineSettings(oCenterline)
Next
Next

 


I have this plate, please see attachment picture

 

Where I want a centerline, vertical and horizontal (the red lines) to illustrate what I mean

 

I can not get the code to work, so I hope I can get help from you.

 

Yours sincerely

 

Steffen

0 Likes
Accepted solutions (1)
1,327 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @sbcJLYKK.  Unless the mostly rectangular cutout in the middle of the part was made with a sheet metal punch tool, you are most likely not going to get a Centermark or Centerline at its center using the automated centerline settings tool.  If the part was modeled centered on the origin planes, and aligned parallel/perpendicular with the origin planes you could turn the visibility of those origin planes on within the view to form the center lines similar to what you seem to be wanting.  To do something like that by code you could use the DrawingView.SetIncludeStatus(oWorkPlane1) method.  That will both 'include' the work plane, but also set its visibility to True.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

sbcJLYKK
Contributor
Contributor
Thank you for your reply😀.
 
I nede a little more help.
 
 I've been working with iLogic for about 14 days, so I'm still a beginner
I need a little more help. I did do a workplane as described
 
Where should I insert DrawingView.SetIncludeStatus(oWork_Plane_Horisontal) in The code
 
Sincerly Steffen
0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Hi @sbcJLYKK.  Sure.  Here is an example of an iLogic rule for the task I mentioned (including the two WorkPlanes in the view).  In this example, I have eliminated the loop of each sheet, and eliminated the loop of each view on each sheet, because this bit of code will only work on specific views that are oriented correctly with the right two work planes.  Only the two work planes that are perpendicular to the view will show properly as lines in the view.  I don't clearly recall right now, but I believe that trying to include the other work plane that is flat with the view may throw an error, because it won't produce any new geometry in the view.  Anyways, this example shows the basic process of how to do this specific task for a drawing view.  I included several lines of comments within the code too, in order to help a bit.  You may need to change the number 1 to a different number if the first view on the sheet is not the right one.  Or we may need to change how we are specifying which view to target.

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
'specify which view to act upon
'you will likely only want to do this with a single view
'in this example, I'm just specifying the first view that was placed on this sheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
'get the model document being referenced by this view
Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
'a generic Document doesn't have WorkPlanes, only parts & assemblies do
'so in order to maintain 'intellisense' recognition going forward
'we must identify the document's specific type, then create that type of variable
'set its value, then work from that new document variable to get the WorkPlanes
If oModel.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oPDoc As PartDocument = oModel
	Dim oWPlanes As WorkPlanes = oPDoc.ComponentDefinition.WorkPlanes
	oYZPlane = oWPlanes.Item("YZ Plane")
	'oXZPlane = oWPlanes.Item("XZ Plane")
	oXYPlane = oWPlanes.Item("XY Plane")
	'only include the two planes that are perpendicular to this view
	'which ever two they may be for your case
	oView.SetIncludeStatus(oYZPlane, True)
	oView.SetIncludeStatus(oXYPlane, True)
End If

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

sbcJLYKK
Contributor
Contributor
Hi
 
Many thanks for your help :).
 
It's really nice of you.
 
I have inserted the code as follows:
 
 
Dim oDoc As DrawingDocument = ThisDoc.Document
 
Dim oSheet As Sheet = oDoc.ActiveSheet 
 
Dim oView As DrawingView = oSheet.DrawingViews.Item(1) 
 
Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument 
 
If oModel.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
 
Dim oPDoc As PartDocument = oModel
 
Dim oWPlanes As WorkPlanes = oPDoc.ComponentDefinition.WorkPlanes oYZPlane = oWPlanes.Item("YZ Plane") 
 
oView.SetIncludeStatus(oXZPlane, True)
 
oView.SetIncludeStatus(oXYPlane, True)
 
End If
 
I have, of course, read the remarks, but I got an error
0 Likes
Message 6 of 8

WCrihfield
Mentor
Mentor

OK.  I could not tell what the error message said, because it was in a language I don't understand, but I was able to download the part and drawing files, and open them OK.  I had to modify the code very slightly, because one of the origin work planes I was using was the wrong one.  So, I simply got rid of the third work plane line of code, then un-commented the second one, then fixed the one 'SetIncludeStatus' line to the correct variable.  Then it worked just as planned.

Here is the exact code I used within a local iLogic rule (saved within the drawing document) and it ran perfectly for me.

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
If oModel.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oPDoc As PartDocument = oModel
	Dim oWPlanes As WorkPlanes = oPDoc.ComponentDefinition.WorkPlanes
	oYZPlane = oWPlanes.Item("YZ Plane")
	oXZPlane = oWPlanes.Item("XZ Plane")
	oView.SetIncludeStatus(oYZPlane, True)
	oView.SetIncludeStatus(oXZPlane, True)
End If

Because the first DrawingView just happened to be the main front view on the drawing, and the two WorkPlanes in the model that are perpendicular to that front view in the part are the two that we want to work with here.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 8

WCrihfield
Mentor
Mentor
Accepted solution

There are several ways to specify exactly which view you want to target, and since we usually want to do it by view name, here is the same iLogic rule that includes a way to get the view by its name.  This is the long way, using Inventor API code, instead of the iLogic shortcut snippet way.  It also worked just fine.

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oView As DrawingView
For Each oDView As DrawingView In oSheet.DrawingViews
	If oDView.Name = "Front_View" Then
		oView = oDView
	End If
Next
If oView Is Nothing Then
	MsgBox("A DrawingView named 'Front_View' was not found. Exiting rule.", vbCritical, "")
	Exit Sub
End If
Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
If oModel.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim oPDoc As PartDocument = oModel
	Dim oWPlanes As WorkPlanes = oPDoc.ComponentDefinition.WorkPlanes
	oYZPlane = oWPlanes.Item("YZ Plane")
	oXZPlane = oWPlanes.Item("XZ Plane")
	oView.SetIncludeStatus(oYZPlane, True)
	oView.SetIncludeStatus(oXZPlane, True)
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

sbcJLYKK
Contributor
Contributor

Many thanks for your help.

 

It's really kind of you.

 

It works now 🙂

0 Likes