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.
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:
(We have thousands of drawings so therefore it is no option to do it by hand.)
Thanks in advance!
Solved! Go to Solution.
Solved by jaconoorland45. Go to Solution.
Solved by JMGunnar. Go to Solution.
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
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
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
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
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
Johan
Can't find what you're looking for? Ask the community or share your knowledge.