Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

To create new layers in the drawing document.

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
RoyWickrama_RWEI
1421 Views, 3 Replies

To create new layers in the drawing document.

I need using a couple of layers in the drawing document to use for creating sketches that need not printing. This is useful in my templates and the drawings in general. Currently, I may name them as Layer_NoPrint1 and Layer_NoPrint2 (for example). I tried my best by referring to internet postings - I have found some which are going to be useful down the road. What I need mostly at present is creating new layers (Layer_NoPrint1 and Layer_NoPrint2 ) in the drawing document. Pl. help. Thanks.
3 REPLIES 3
Message 2 of 4

Hi,

 

I am not sure if you need this in iLogic, or some other environment. You can use the Inventor API to create a layer. This VBA example in the SDK help creates a new layer:

Public Sub Layer()

 

The help is here on my system:

"C:\Program Files\Autodesk\Inventor 2014\Local Help\admapi_18_0.chm"

 

Below is a simpler VBA example.

 

I found I had to use the Internal name to get the Layer I was going to copy from. (or use the number). You can see the internal name in the Watch window. I find that using VBA is a good way to get things working and then move to VB.NET or some other environment.  iLogic rules can use VB.NET code however in this case I am not sure using iLogic is the way to go as you may as well just have an idw that you use as a template with the layers already there.

 

Public Sub LayerAddTest()
   
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
   
'    Dim oLayers As LayersEnumerator
'    Set oLayers = oDrawDoc.StylesManager.Layers
   
    Dim oLayer As Layer
    ' Set oLayer = oDrawDoc.StylesManager.Layers.Item(68)
    Set oLayer = oDrawDoc.StylesManager.Layers.Item("1:Copy (1) of 3D Sketch Geometry (ISO)")
   
    Dim oNewLayer As Layer
    Set oNewLayer = oLayer.Copy("waynes_layer_copy")
   
    oNewLayer.color = ThisApplication.TransientObjects.CreateColor(0, 0, 255)

End Sub

 

Thanks,

Wayne

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

Thanks a lot. With a little modification (to match with my current entry level knowledge), I am getting it done. I also thought of adding a Try ... Catch ... End Try. But, it is not working well - my Try is incorrect, I believe. Could you fix this for me. I should learn more for sure. I went to the SDK. Thanks for letting me know about it. I could see the Methods and Properties for example for the Layer Object: will explore them. I need learning to improve - Could you advise me some formal steps to go through.
Message 4 of 4

Thank you very much. This saved me hours of work. My specific problem was that i had to change the layer color via a vba macro. I just couldnt figure it out untill I stumbled upon your code from which I could get several clues how to do it. 😅

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums