automated centrelines using ilogic

automated centrelines using ilogic

PG_Tips
Contributor Contributor
2,540 Views
9 Replies
Message 1 of 10

automated centrelines using ilogic

PG_Tips
Contributor
Contributor

hi,

i have tried using the automated centerlines on inventor and it either does too much or too little for my use.

i have tried ilogic codes available on the forum but nothing has worked fully so far. 

basically we have items on our library and we mostly use them to create assembly files and drawings.

i was thinking if i could make the axis of the individual parts visible on the drawing, this would somewhat visually work as a centreline. doing it manually works perfectly but it is more time consuming than using the centreline feature. 

i have found a code that makes the required axis visible on a drawing but it only does it for one item.

is it possible to make it do it for all parts in the assembly?

 

Dim oDoc As DrawingDocument
  	oDoc = ThisApplication.ActiveDocument
   	Dim oView As DrawingView = ActiveSheet.View("FRONT VIEW").View
	Dim oAssyDoc As AssemblyDocument = ActiveSheet.View("FRONT VIEW").ModelDocument
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oPt As Point2d = oTG.CreatePoint2d
	
	Dim oOcc1 As ComponentOccurrence = oAssyDoc.ComponentDefinition.Occurrences.AllLeafOccurrences.Item(1)

    Dim oSheet As Sheet
    oSheet = oDoc.ActiveSheet
	
	Dim oDocDef1 As Document = oOcc1.Definition.Document
	
	Dim oWA1 As WorkAxis = oDocDef1.ComponentDefinition.WorkAxes.Item("X Axis")
	Dim oWAP1 As WorkAxisProxy							'	For Each myAxis In oDocDef1.ComponentDefinition.WorkAxes
												'		If myAxis.Name = "InletRefAxis" Then oWA1 = myAxis
												'	Next
	
	oOcc1.CreateGeometryProxy(oWA1, oWAP1)
	Dim oCL1 As Centerline
	oCL1 = oSheet.Centerlines.AddByWorkFeature(oWAP1, oView)

 

0 Likes
Accepted solutions (4)
2,541 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Hi @PG_Tips.  It looks to me like that rule digs down into the model document, which is an assembly in this case, finds a specific component, finds the WorkAxis named "X Axis" specifically, then makes it visible within that one drawing view.

Can you answer each of these points please?

Do you want:

  • Loop through all sheets in the drawing
    • If not, how would you like to specify which sheet for it to process
  • Loop through all views on the sheet
    • If not, how would you like to specify which view for it to process
  • Only process the drawing view's model if it is an Assembly
    • Or only process the drawing view's model if it is a Part
    • Or process the drawing view's model no matter what type of model document it is
  • If it's an assembly, loop through every component in it, making its "X Axis" visible in the drawing
    • Or only find certain specific components to process (for example, by their names, or other unique spec)
    • If looping through all components, how many layers deep through sub-assemblies?
    • Only process components representing parts, or include sub-assemblies too?
  • Do you only want that one specific WorkAxis made visible, or are there other WorkAxes, WorkPlanes, WorkPoints you would like to have made visible in the drawing view?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

PG_Tips
Contributor
Contributor
  • Loop through all sheets in the drawing
    • If not, how would you like to specify which sheet for it to process

We always have 1 sheet per drawing so the rule will always apply to sheet 1.

 

  • Loop through all views on the sheet
    • If not, how would you like to specify which view for it to process

The name of the views are always "FRONT VIEW", "SIDE VIEW" and "PLAN VIEW". so the code will need to first determine which view it is and then make either x, y or z axis visible.

 

  • Only process the drawing view's model if it is an Assembly
    • Or only process the drawing view's model if it is a Part
    • Or process the drawing view's model no matter what type of model document it is

the code is for an assembly file. for a part file it is easy enough to do it manually without taking too long.

 

  • If it's an assembly, loop through every component in it, making its "X Axis" visible in the drawing
    • Or only find certain specific components to process (for example, by their names, or other unique spec)
    • If looping through all components, how many layers deep through sub-assemblies?
    • Only process components representing parts, or include sub-assemblies too?

the axis of all part need to be visible no matter how many sub assemblies. also key note is not to make the axis of an assembly visible, only parts. ideally i will like to be able to choose the axis depending on file name or stock number, but this is not super important. at the moment i will be happy if certain axis are visible depending on the view.

 

  • Do you only want that one specific WorkAxis made visible, or are there other WorkAxes, WorkPlanes, WorkPoints you would like to have made visible in the drawing view?

just origin axis of individual parts. 

0 Likes
Message 4 of 10

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, I have modified your code a bit and I wonder if this could help you

 

	Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet = oDoc.ActiveSheet
   	Dim oView As DrawingView = ActiveSheet.View("FRONT VIEW").View
	Dim oAssyDoc As AssemblyDocument = ActiveSheet.View("FRONT VIEW").ModelDocument

	Dim oWAP1 As WorkAxisProxy	
	Dim oCL1 As Centerline
	
	For Each oOcc As ComponentOccurrence In oAssyDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
		Try
			Dim oDocDef As Document = oOcc.Definition.Document
			Dim oWA1 As WorkAxis = oDocDef.ComponentDefinition.WorkAxes.Item("X Axis")
			oOcc.CreateGeometryProxy(oWA1, oWAP1)
			oCL1 = oSheet.Centerlines.AddByWorkFeature(oWAP1, oView)
		Catch
		End Try
	Next

 I hope this helps with your work, or allows you to develop it better, regards!!


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 5 of 10

WCrihfield
Mentor
Mentor
Accepted solution

The code @Sergio.D.Suárez posted is very similar to what I was going to post, so I won't bother posting my version.  However, there is another option available as an alternative to that last line of code in the loop I thought I would post here, just so you are aware of it.

This line:

oCL1 = oSheet.Centerlines.AddByWorkFeature(oWAP1, oView)

That line uses a method that creates a Centerline object on the sheet to represent the work axis found in the view.

Could be replaced by this line too:

oView.SetIncludeStatus(oWAP1, True)

This line is basically the same as if you had expanded the model browser nodes below the view and right-clicked on an the origin axis of the component, then chose 'Include' from that right-click menu, which makes that object show in the view.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 10

PG_Tips
Contributor
Contributor

@Sergio.D.Suárez  and @WCrihfield thank you both for the code. it did exactly what i wanted it to do but the library parts are very inconsistent with axis views and i am having to delete a lot of them to show exactly what i need. i have noticed though using inventor system automated centerline feature i can get the centerlines i need. basically if i just select the revolved feature and both projection option i can get the centerline i need (see picture attached). could you help me create a code that will do this for FRONT, SIDE AND TOP VIEW only in a drawing.Capture.PNG

0 Likes
Message 7 of 10

theo.bot
Collaborator
Collaborator
Accepted solution

This code will work. I use this in my template as well (without checking the name of the view and with different options).



Dim
oDoc As DrawingDocument oDoc = ThisDoc.Document 'set automatic centerline settings Dim settings As AutomatedCenterlineSettings settings = oDoc.DrawingSettings.AutomatedCenterlineSettings settings.ApplyToBends = False settings.ApplyToCircularPatterns = False settings.ApplyToCylinders = False settings.ApplyToFillets = False settings.ApplyToHoles = False settings.ApplyToPunches = False settings.ApplyToRectangularPatterns = False settings.ApplyToRevolutions = True settings.ApplyToSketches = False settings.ApplyToWorkFeatures = False settings.ProjectionNormalAxis = True settings.ProjectionParallelAxis = True settings.ApplyToCircularPatterns = true 'settings.FilletRadiusMinimumThreshold = 2.5 ''settings.FilletRadiusMaximumThreshold = ''settings.CircularEdgeMinimumThreshold = ''settings.CircularEdgeMaximumThreshold = 'loop thru views and add centerlines Dim oView As DrawingView For Each oView In oDoc.ActiveSheet.DrawingViews If oView.Name = "TOP" Or oView.Name = "FRONT" Or oView.Name = "SIDE" Call oView.SetAutomatedCenterlineSettings(settings) End If Next

 

Message 8 of 10

PG_Tips
Contributor
Contributor

@theo.bot thank you for the code, it works perfectly.

 

although both codes do what i want, its not giving me the result i desire. activating both codes as external rule gives me the best result and i am happy with that for the time being.

@WCrihfield @Sergio.D.Suárez i made some changes to the code to work for my application the best. i am running into a problem, if either of FRONT, SIDE OR PLAN view do not exist on the drawing, it gives me an error. is there a way for the code to work even when missing some view. not all drawings have all three views. my drawing will always have a front view but side and plan are dependent on different projects.

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Give this version a try.  I made a list of the view names we will try to process before the loop, then within the loop, use a second loop to go through those view names, using a Try...Catch...End Try block so it won't throw an error if that view name is not found.  I also put a Try...Catch block around where it attempts to get that WorkAxis named "Work Axis1", so that won't throw an error if not found.  Sometimes it's nice to have feedback about error's that get handled, so you can potentially deal with them or learn from them later, so I included a message or Log entry in the Catch area of those blocks, but left them commented out for now.

Dim oDoc As DrawingDocument = ThisDrawing.Document
Dim oAssyDoc As AssemblyDocument  = ThisDrawing.ModelDocument
oSheet = oDoc.ActiveSheet
Dim oViewNames As New List(Of String)
oViewNames.AddRange({"FRONT VIEW", "PLAN VIEW", "SIDE VIEW"})
oOccs = oAssyDoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs.AllLeafOccurrences
	'LeafOccurrences will be Parts, not Assemblies
	Dim oPDoc As PartDocument = oOcc.Definition.Document
	Dim oWA1 As WorkAxis
	Try
		oWA1 = oPDoc.ComponentDefinition.WorkAxes.Item("Work Axis1")
	Catch oEx As Exception
		'MsgBox(oEx.Message & vbCrLf & oEx.StackTrace, vbExclamation, "iLogic")
		'Logger.Error("{0}" & vbCrLf & "{1}", oEx.Message, oEx.StackTrace)
		'couldn't find that WorkAxis
		Continue For 'skip to next oOcc
	End Try
	Dim oWAP1 As WorkAxisProxy
	oOcc.CreateGeometryProxy(oWA1, oWAP1)
	For Each oViewName In oViewNames
		Try
			oView = ActiveSheet.View(oViewName).View
			oView.SetIncludeStatus(oWAP1, True)
		Catch oEx As Exception
			'either couldn't find that view, or SetIncludeStatus failed
			'MsgBox(oEx.Message & vbCrLf & oEx.StackTrace, vbExclamation, "iLogic")
			'Logger.Error("{0}" & vbCrLf & "{1}", oEx.Message, oEx.StackTrace)
		End Try
	Next
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 10

PG_Tips
Contributor
Contributor

thank you @WCrihfield this works perfectly.

0 Likes