SetAutomatedCenterlineSettings not working

SetAutomatedCenterlineSettings not working

CAD_CAM_MAN
Advocate Advocate
402 Views
8 Replies
Message 1 of 9

SetAutomatedCenterlineSettings not working

CAD_CAM_MAN
Advocate
Advocate

Using Inventor 2025.2.1. 

I am struggling to get automated centerlines working in an add-in I am creating. When using the Automated centerlines command manually the centerlines and center marks are applied as expected. However the code below does not yield any results. That is it does not add any centerlines or center marks to the base view. Comparing to other examples it seems it should work. Can somebody point out what I am missing?

  POSheet = PrintDoc.Sheets.Add(SheetSize, SheetOrientation, PO.FileNameWithState)
    Dim BaseView As DrawingView = POSheet.DrawingViews.AddBaseView(CType(PO.Doc, _Document), PO.BaseViewPoint, PO.BaseViewScale, PO.BaseViewOrientation, PO.BaseViewStyle)
  Dim ACLSettings As AutomatedCenterlineSettings = PrintDoc.DrawingSettings.AutomatedCenterlineSettings
  ACLSettings.ApplyToCylinders = True
  ACLSettings.ApplyToHoles = True
  ACLSettings.ApplyToRevolutions = True
  ACLSettings.ApplyToRectangularPatterns = True
  ACLSettings.ProjectionNormalAxis = True
  ACLSettings.ProjectionParallelAxis = True
  BaseView.SetAutomatedCenterlineSettings(ACLSettings)

 

0 Likes
403 Views
8 Replies
Replies (8)
Message 2 of 9

CAD_CAM_MAN
Advocate
Advocate

Help anybody ?!?!?!

Since I cannot figure out what the issue is with the current code I am now trying to access via the command manager. However still not getting center lines or center marks. Can anybody help from this direction?

 With PrintDoc.SelectSet
     .Clear()
     .Select(BaseView)
 End With

 Dim CM As CommandManager = G_IApp.CommandManager
 Dim CMCDef As ControlDefinition = CM.ControlDefinitions.Item("DrawingAutoCenterMarkCmd")
 CMCDef.Execute()

 

0 Likes
Message 3 of 9

WCrihfield
Mentor
Mentor

Hi @CAD_CAM_MAN.  I don't really see anything wrong with the code contents, but there may be other factors influencing this behavior that the rest of us can not see.  I am not that familiar with doing things through an add-in, but one thing that comes to mind is that the Sheet being worked on by that code most likely needs to be the 'active' sheet (actually visible on the screen at that time) of the 'active' document.  I don't think you can apply those settings to the views on in-active sheets.  But that is just one possible complication involved in the process, while there may be more.  Another possible small detail that may prevent this from working correctly is if the view is not looking 100% perfectly squarely at the model, or the model is not 100% perfectly square with the view.  When that is the case, the round holes may be ellipses, and the arcs may be elliptical arcs.  I have seen that scenario before on multiple occasions, but don't recall the series of events that lead to that happening.

As for doing selections and command executions, in an attempt to simulate user interactions, those can be tricky to get working correctly also.  Once again, the drawing would need to be the 'active' one, and that sheet that the view was on would need to be the 'active' one.  But also, depending on what else may have been going on just before that section of code is acted out, you may need to ensure that the 'system focus' is on the Inventor application, instead of elsewhere.  To ensure that, I used to use the simplistic AppActivate(ThisApplication.Caption) type line of code.  Just throwing some thoughts around, but not sure if any of them are the real issue, if if any of them will help any.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

CAD_CAM_MAN
Advocate
Advocate

Thank you for those points @WCrihfield. Of course I would much prefer to NOT use the command manger but I am getting desperate! SetAutomatedCenterlineSettings does not not seem to be working per the admapi documentation (at least best I intepret it). I tried POSheet.activate with no results. The Baseview is 100% square with round features and will yield the correct results when using automatic centerlines manually. In hopes of resolving this issue and my sanity I have cut my add in down to a simple ilogic rule. I have embedded the rule in the attached part file as well. If the rule is ran from a part file it creates a drawing and a front view but fails to add any centerlines or center marks. Any further advisement is much appreciated!

Sub Main

        Dim PrintDoc As DrawingDocument
		Dim PODoc As PartDocument = ThisApplication.ActiveDocument 
		PrintDoc = TryCast(ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , True), DrawingDocument)
		If PrintDoc Is Nothing Then Exit Sub
		POSheet = PrintDoc.Sheets(1)
		BaseViewPoint = ThisApplication.TransientGeometry.CreatePoint2d(10,10) 
		Dim BaseView As DrawingView = POSheet.DrawingViews.AddBaseView(CType(PODoc, _Document), BaseViewPoint, 2.0, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
		POSheet.Activate 
		 Dim ACLSettings As AutomatedCenterlineSettings = PrintDoc.DrawingSettings.AutomatedCenterlineSettings
		 ACLSettings.ApplyToCylinders = True
		 ACLSettings.ApplyToHoles = True
		 ACLSettings.ApplyToRevolutions = True
		 ACLSettings.ApplyToRectangularPatterns = True
		 ACLSettings.ProjectionNormalAxis = True
		 ACLSettings.ProjectionParallelAxis = True
		 BaseView.SetAutomatedCenterlineSettings(ACLSettings)
		 PrintDoc.Update()

End Sub

 

0 Likes
Message 5 of 9

JelteDeJong
Mentor
Mentor

I changed your code a bit to run as an iLogic rule.

Dim PrintDoc As DrawingDocument = ThisDoc.Document
Dim POSheet = PrintDoc.ActiveSheet
Dim BaseView As DrawingView = POSheet.DrawingViews.Item(1)

Dim ACLSettings As AutomatedCenterlineSettings = PrintDoc.DrawingSettings.AutomatedCenterlineSettings
ACLSettings.ApplyToCylinders = True
ACLSettings.ApplyToHoles = True
ACLSettings.ApplyToRevolutions = True
ACLSettings.ApplyToRectangularPatterns = True
ACLSettings.ProjectionNormalAxis = True
ACLSettings.ProjectionParallelAxis = True

BaseView.SetAutomatedCenterlineSettings(ACLSettings)

 This works for me. That makes me think that your code is working from line 5.  Maybe you can run your code (and see if the views are created) and then run this rule.

It should add centre lines to the first view of the active sheet.

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 6 of 9

CAD_CAM_MAN
Advocate
Advocate

Thank you for the response @JelteDeJong. I am able to get the centerlines to appear using your rule attached to the drawing that is created from the original rule. However this has not helped me understand why the original rule posted does not work. As @WCrihfield pointed out there may be other conditions that need to be met. Which appears to be the case. PrintDoc = ThisDoc.Document seems to do something that Printdoc = ThisApplication.Documents.Add is not doing. How do I get PrintDoc in context of ThisDoc.Document from ThisApplication.Documents.Add? I have tried activating and updating PrintDoc and POSheet etc with no results.

0 Likes
Message 7 of 9

JelteDeJong
Mentor
Mentor

I did some more tests and could reproduce the problem. I could solve the problem by activating the document before adding the centerlines. So the solution in my situation is on line 12

Dim PrintDoc As DrawingDocument = ThisDoc.Document
Dim partDoc As PartDocument = ThisApplication.Documents.Open("D:\forum\bakje.ipt")
Dim BaseViewPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(25, 20)
Dim BaseViewScale As Double = 0.4
Dim BaseViewOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kFrontViewOrientation
Dim BaseViewStyle As DrawingViewStyleEnum = DrawingViewStyleEnum.kShadedHiddenLineDrawingViewStyle


Dim POSheet = PrintDoc.Sheets.Add()
Dim BaseView As DrawingView = POSheet.DrawingViews.AddBaseView(partDoc, BaseViewPoint, BaseViewScale, BaseViewOrientation, BaseViewStyle)

PrintDoc.Activate()

Dim ACLSettings As AutomatedCenterlineSettings = PrintDoc.DrawingSettings.AutomatedCenterlineSettings
ACLSettings.ApplyToCylinders = True
ACLSettings.ApplyToHoles = True
ACLSettings.ApplyToRevolutions = True
ACLSettings.ApplyToRectangularPatterns = True
ACLSettings.ProjectionNormalAxis = True
ACLSettings.ProjectionParallelAxis = True

BaseView.SetAutomatedCenterlineSettings(ACLSettings)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 8 of 9

CAD_CAM_MAN
Advocate
Advocate

The premise of the add-in is to build drawings from parts or assemblies at runtime. So I can not run from a drawing that does not exist yet and therefore am struggling to see how to use Dim PrintDoc as DrawingDocument = ThisDoc.Document. I apologize if I am missing the point!

By changing only lines 1 and 2 to run from a part instead of the drawing it fails... WHY?!?!?!?!?!?!🤕

Dim PrintDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , True)
Dim partDoc As PartDocument = ThisDoc.Document 
Dim BaseViewPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(25, 20)
Dim BaseViewScale As Double = 0.4
Dim BaseViewOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kFrontViewOrientation
Dim BaseViewStyle As DrawingViewStyleEnum = DrawingViewStyleEnum.kShadedHiddenLineDrawingViewStyle


Dim POSheet = PrintDoc.Sheets.Add()
Dim BaseView As DrawingView = POSheet.DrawingViews.AddBaseView(partDoc, BaseViewPoint, BaseViewScale, BaseViewOrientation, BaseViewStyle)

PrintDoc.Activate()

Dim ACLSettings As AutomatedCenterlineSettings = PrintDoc.DrawingSettings.AutomatedCenterlineSettings
ACLSettings.ApplyToCylinders = True
ACLSettings.ApplyToHoles = True
ACLSettings.ApplyToRevolutions = True
ACLSettings.ApplyToRectangularPatterns = True
ACLSettings.ProjectionNormalAxis = True
ACLSettings.ProjectionParallelAxis = True

BaseView.SetAutomatedCenterlineSettings(ACLSettings)

 

0 Likes
Message 9 of 9

WCrihfield
Mentor
Mentor

Just dropping a link here to another forum discussion about automated centerlines/marks back in 2021, where we encountered another problem preventing them from being added to the views as we wanted them to be.  The part was cylindrical, but real hole features were used to place holes through the sides of the cylinder that were perfectly passing through the center axis of the part.  There were two sets of holes which were perpendicular to each other, so that they would be 'flat' with the standard views of the part in the drawing.  We even created section views of it, so that we would get the two parallel lines of the holes through the part.  But that auto tool would not recognize them.  Likely due to there not being true, flat, circular edges.

https://forums.autodesk.com/t5/inventor-programming-ilogic/automated-centerlines/m-p/10764592 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes