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: 

Use VBA to set color option to "By Layer"

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
jaconoorland45
655 Views, 8 Replies

Use VBA to set color option to "By Layer"

Hi all,

 

Before we make exports to PDF we need to change the line color of objects using the following code and this works perfect:

 

{

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

Dim oLayer As Layer

Set oLayer = oDrawDoc.StylesManager.Layers.Item("HIS_0")
oLayer.Color = ThisApplication.TransientObjects.CreateColor(0, 0, 0)

}

 

(This is used for about 20 different layers)

 

The only problem is that in some inventor drawings, the color of some specific objects isn't referenced to a layer with the "By Layer" option. So if we change the layer color the color of the object stays the same.

 

jaconoorland45_0-1655980171556.png

 

Is there any code in VBA available to change the color of the object (e.g. Dimensions or Hatch or anything) to "By Layer"? So it looks like this:

 

jaconoorland45_2-1655980381371.png

(We have thousands of drawings so therefore it is no option to do it by hand.)

 

Thanks in advance!

Labels (6)
8 REPLIES 8
Message 2 of 9
JMGunnar
in reply to: jaconoorland45

You need too get DimensionStyles

 

and then you can set oDimension.color too Nothing

 

Best Regards Johan 

 

 

Dim oDrawDoc As DrawingDocument
        oDrawDoc = ThisApplication.ActiveDocument

Dim oDimension As DimensionStyle
   Set     oDimension = oDrawDoc.StylesManager.DimensionStyles.Item("Dimension")

oDimension.Color = Nothing

Message 3 of 9

I am going to try it immidiately. Thanks for your help!

Message 4 of 9

It Worked!! I am very happy, thanks a lot.😅

 

There was a little mistake in your code. You forgot "Set" before oDrawDoc.

 

So here is the code which works for me:

 

Public Sub editedit()

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

Dim oDimension As DimensionStyle
Set oDimension = oDrawDoc.StylesManager.DimensionStyles.Item("HIS_DIMENSION")

oDimension.Color = Nothing

End Sub

 

 

Message 5 of 9
jaconoorland45
in reply to: JMGunnar

@JMGunnar 

 

So after printing we need to reverse it too its original color. Is this possible? So we need to uncheck the "By Layer" option so it reverts to its previously color.   

Message 6 of 9

@JMGunnar 

 

I already found a solution for this by storing the RGB Value and then recalling it later.

 

Public Sub editedit2()

Dim oldcolor As Color
Dim oDrawDoc As DrawingDocument

Set oDrawDoc = ThisApplication.ActiveDocument

Dim oDimension As DimensionStyle

Set oDimension = oDrawDoc.StylesManager.DimensionStyles.Item("HIS_DIMENSION")

Set oldcolor = oDimension.Color

MsgBox ("It Works! COLOR VALUE:" & test)

oDimension.Color = Nothing

MsgBox ("It Works! COLOR VALUE:" & test)

oDimension.Color = oldcolor

End Sub

Message 7 of 9
JMGunnar
in reply to: jaconoorland45

Congratulations @jaconoorland45 

 

I create the code in ilogic and not VBA 

that's why i forgot SET in VBA

 

Autodesk ends with VBA in Inventor in future versions

 

Best Regards Johan 

 

Message 8 of 9

Will my VBA modules become obselete? 😥

Message 9 of 9
JMGunnar
in reply to: jaconoorland45

I recommend starting to use ilogic

VBA will be retired.

 

 

 

As an alternative to VBA, consider using Inventor’s iLogic capability. It provides access to the Inventor API using VB.NET. You can learn more about iLogic 

 

https://adndevblog.typepad.com/manufacturing/2015/11/convert-vba-to-net-ilogic.html

 

https://knowledge.autodesk.com/support/inventor/downloads/caas/downloads/content/download-the-micros...

 

Johan

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report