Automated Centerlines iLogic

Automated Centerlines iLogic

Anonymous
Not applicable
2,673 Views
2 Replies
Message 1 of 3

Automated Centerlines iLogic

Anonymous
Not applicable

I have found parts of some code and written the rest to place automated centerlines on holes and projected parallel axis on all views on a drawing.  But I am having some trouble with the code.  It will place the centerlines on the holes but not the projected parallel axis.  Also, the remove unattached centerlines is not working.  I'm sure I just have a small error somewhere but I am missing it.  Thanks in advance!

 

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 9446 StartFragment: 314 EndFragment: 9414 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

'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 view add centerlines to holes and projection parallel axis
For Each oSheet In oSheets
oViews = oSheet.DrawingViews
    For Each oView In oViews
Dim oCenterline As AutomatedCenterlineSettings
oView.SetAutomatedCenterlineSettings(oCenterline)
       oCenterline.ApplytoHoles  = True
       oCenterline.ProjectionParallelAxis = True
        
        
    Dim resultCenters As ObjectsEnumerator
    resultCenters = oView.SetAutomatedCenterlineSettings(oCenterline)
 Next
 Next

' Delete all unattached centerlines

For Each centerLine In oSheet.CenterLines 

  If (Not centerLine.Attached) Then  

    centerLine.Delete() 

  End If

Next
2,674 Views
2 Replies
Replies (2)
Message 2 of 3

wayne.brill
Collaborator
Collaborator

Hi,

 

I used your rule and I am getting "Object reference not set to an instance of an object." on this line:

 oCenterline.ApplytoHoles  = True

 

I find that I needed to have this line to avoid the error. (instantiates the oCenterline variable)

oView.GetAutomatedCenterlineSettings(oCenterline)

 

To get the rule to create the center lines I had to move these lines

oCenterline.ApplytoHoles  = True
oCenterline.ProjectionParallelAxis = True

 

Before this line:       
oView.SetAutomatedCenterlineSettings(oCenterline)

 

Here is the for loop that is working for me:

 

For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    
    For Each oView In oViews
        Dim oCenterline As AutomatedCenterlineSettings
        'WB added
        oView.GetAutomatedCenterlineSettings(oCenterline)
        'WB moved here
        oCenterline.ApplytoHoles  = True
        oCenterline.ProjectionParallelAxis = True
        
        oView.SetAutomatedCenterlineSettings(oCenterline)
       ' oCenterline.ApplytoHoles  = True
       ' oCenterline.ProjectionParallelAxis = True
        
'        Dim resultCenters As ObjectsEnumerator
'        resultCenters = oView.SetAutomatedCenterlineSettings(oCenterline)
    Next
 Next

 

Let me know if the results you get.

 

Also I find it helpful to have variable names indicate what they are. (naming an AutomatedCenterlineSettings object oCenterLine is confusing to me)

 

I did not test the problem with deleting the center lines. Please upload a drawing that has center lines that are not attached. (called sick in the API help)

 

Thanks,

Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 3

dusan.naus.trz
Advisor
Advisor

Hi all,

 

I had the same problem. thank you for solutions. thumbs up. It could be a service pack or update for 2017?

0 Likes