VBA changing layer of views

VBA changing layer of views

basnederveen
Advocate Advocate
2,478 Views
11 Replies
Message 1 of 12

VBA changing layer of views

basnederveen
Advocate
Advocate

Hi,

 

I am trying to make a script that exports my current opened drawing to dwg. To do this I want to be sure no views or other objects have been placed outside the borders of the drawing. 

 

If views/other objects are placed outside of these border, I want to change them to a layer which I will then turn off before exporting. Currently this is all going really well except for one part; Data from reference parts is not changed. (see attached pic). It is very strange because changing the visibility does work on these lines. 

 

To select the curves, im just cycling through all views, if they are outside then loop through each curve and for each curve loop through each segment, I add all these lines to an Object COllection and then change it in the end.

 

 

My question:


Is there a way to select the Off option in the reference data; line style using VBA? (see 2nd pic)

 

or 

 

Is there a way to change the layer of the reference curves?

 

 

 

 

 

 

 

0 Likes
2,479 Views
11 Replies
Replies (11)
Message 2 of 12

basnederveen
Advocate
Advocate
I looked in the object browser and i cant find anything about it. I think this is an unsupported feature..

0 Likes
Message 3 of 12

MechMachineMan
Advisor
Advisor

Drawing View -> Drawing Curves -> Drawing Curve Segments -> Layer

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-A9022D3F-50BF-46AD-96A1-D2FB0D743A37


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 12

basnederveen
Advocate
Advocate
That is what I'm doing right now, but it skips the curves in the picture
0 Likes
Message 5 of 12

MechMachineMan
Advisor
Advisor

K. Well, I have nothing more to go on.

 

If you were to post a screen cast of the code running, the code, or both, there might be more progress to be had.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 6 of 12

basnederveen
Advocate
Advocate
I'm sorry, i wanted to post the code but left it at work pc.

This is the just the loop.

Dim oCurve As DrawingCurve
For Each oCurve In oDrawView.DrawingCurves

' Add all curve segments in the view to an object collection
Dim oSegment As DrawingCurveSegment
For Each oSegment In oCurve.Segments
objColl.Add oSegment

' Next segment
Next

' Next Curve
Next
End If

' Change the layer of all curves in collection, placing the call here will change after looped through 1 view
' Call oDrawView.Parent.ChangeLayer(objColl, oLayer)
' Next view
Next

0 Likes
Message 7 of 12

MechMachineMan
Advisor
Advisor

It's definitely possible.

 

Here's some code to study. Took me about 15 minutes to look up the necessary API objects and write it.

 

Stole some snippets from here

 

Sub Main()

    Dim oDoc As Document = ThisDoc.Document
    Dim oTG As TransientObjects = ThisApplication.TransientObjects
    Dim objColl As ObjectCollection = oTG.CreateObjectCollection
    Dim oCurve As DrawingCurve
    
    Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "Change Layers Rule")
    
    Dim oSS As SelectSet = oDoc.SelectSet
    
    oNewLayer = SelectLayer(oDoc)
    
    For Each oSheet In oDoc.Sheets
        oSheet.Activate
        ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomallCmd").Execute    
        
        For Each oDrawingView In oSheet.DrawingViews
            oSS.Select(oDrawingView)
            If MsgBox("Change Layer of this view?", MsgBoxStyle.YesNo, "MacroMagic") = vbYes Then
                For Each oCurve In oDrawingView.DrawingCurves
                    Dim oSegment As DrawingCurveSegment
                    For Each oSegment In oCurve.Segments
                        objColl.Add(oSegment)
                    Next
                Next
                Call oDrawingView.Parent.ChangeLayer(objColl, oNewLayer)
                objColl.Clear
            End If
            oSS.Clear
        Next
    Next
    
    oTrans.End
End Sub

Function SelectLayer(oDwgDoc As DrawingDocument) As Layer
    Dim oStylesMgr As DrawingStylesManager
    oStylesMgr = oDwgDoc.StylesManager
    
    Dim oList As New List(Of String)
    
    For Each oLayer In oStylesMgr.Layers
        oList.Add(oLayer.InternalName)    
    Next

    oReturnLayerName = InputListBox("Select Layer to Change to", oList, "", Title := "Layer Selector", ListName := "Layers")
    
    Dim oReturnLayer As Layer
    oReturnLayer = oStylesMgr.Layers.Item(oReturnLayerName)
    Selectlayer = oReturnLayer
End Function 

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 8 of 12

basnederveen
Advocate
Advocate
Thanks, but that aas not not my question. I think i miss formulated my topic title. The problem is that after running that, the reference curves are not changed layer. As seen in the picture the script changes all lines to pink apart from the objects set as reference.
0 Likes
Message 9 of 12

basnederveen
Advocate
Advocate

I've found out some more things.

 

- When i added a watch to thisapplication and looked what my selectset contained when selecting a reference curve, i found that the macro did change the layer. Just the curve didnt change color.

- When I select a reference part, the selectset gives me the following:

 

ObjectType = kUnknownObject

Type = kGenericObject

 

So it seems really not possible (IV 2015) to change the reference data to 'Off' through inventor VBA.

 

 

For now I've solved the problem by just suppressing the view instead of placing it in a layer and then hiding it..

 

 

 

0 Likes
Message 10 of 12

Anonymous
Not applicable

thanks for your generous!

I try to run it but met some error, 

0 Likes
Message 11 of 12

MechMachineMan
Advisor
Advisor
Can you elaborate?

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 12 of 12

bbailey6E5PN
Contributor
Contributor

Could you please link where you found the necessary API objects to write this code? I am trying to figure out how to modify this to change all layers to our "0" layer but leave the "Hidden" lines layer alone. 

 

Right now this code will change my "PrimaryPart" layer to "0" but it also changes the hidden lines to "0" as well. 

 

I am in the learning stages of coding and I am very basic at this time. Learning from YT and books people suggest but right now I am struggling. 

 

Thanks for any help on this subject. 

 

Before Rule:

bbailey6E5PN_0-1724850379539.png

 

After Rule:

bbailey6E5PN_1-1724850412732.png

 

Wanted Result:

bbailey6E5PN_2-1724850450754.png

 

 

0 Likes