Control colors of the MarkStyle

Control colors of the MarkStyle

Maxim-CADman77
Advisor Advisor
556 Views
8 Replies
Message 1 of 9

Control colors of the MarkStyle

Maxim-CADman77
Advisor
Advisor

I'd like to know how to control colors of the MarkStyle trough API.

 

I've created a primitive iLogic-rule that I hoped would do the desired:

 

 

If Not TypeOf ThisDoc.Document Is PartDocument Then MsgBox("Not a part") : Return

Dim pDoc As PartDocument = ThisDoc.Document

If pDoc.ActiveMarkStyle Is Nothing Then MsgBox("There is no active mark style") : Return

Dim actMrkStyle = pDoc.ActiveMarkStyle
logger.info("actMrkStyle.Name: " & actMrkStyle.Name)

Dim fColor As Color = actMrkStyle.FrontLayerColor

Dim initRcode = fColor.Red

fColor.SetColor(0, 0, 0)

MsgBox("initial: " & initRcode & vbLf & "new: " & fColor.Red, , "Red-code")

 

 

It reads initial Red-value of the FrontLayerColor (Yellow), sets new Color value (0,0,0 - Black) and finally reads/prints both initial (255) and new (0) Red-values.

New printed value corresponds to the expectations .. but .. if the rule is run for the second time it then prints that same initial red value (255) as during first rule run and I don't see any color changes in UI either.

MaximCADman77_0-1728107507594.png

 

See attached the sample part model to reproduce the described (it is taken from "Get Started with Mark Feature" interactive tutorials for Inventor 2023).

 

PS:
@MjDeck could you please look at this case?

 

PPS:
I've tried Inventor 2024.3.2 and 2025.1.2 and have got the same result.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
557 Views
8 Replies
Replies (8)
Message 2 of 9

MjDeck
Autodesk
Autodesk
Accepted solution

Hi Maxim - when you get the value of MarkStyle.FrontLayerColor, it gives you a copy of the color. Changing the values on that color object will not cause the new value to be written back to Inventor. You have to explicitly write the whole object back. Add the line

 

actMrkStyle.FrontLayerColor = fColor

 

after the call to fColor.SetColor.

Color properties are different in this way from other properties that return more complicated objects.

A hint for this behavior is in the documentation for MarkStyle.FrontLayerColor . It is a read/write property. You can get it and set it. I think all Color properties in the API are like this. You have to assign them back as a complete Color object.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 9

Maxim-CADman77
Advisor
Advisor

The line does the trick - Thank you.


Yet code of real project is a bit more complicated and the line suggested produces that notorious 80004005 Exception on the first run.

Dim newMarkStyleName = "Mark Surface (AV)"

If Not TypeOf ThisDoc.Document Is PartDocument Then MsgBox("Not a part") : Return

Dim pDoc As PartDocument = ThisDoc.Document

Dim newMarkStyle As MarkStyle ' Inv 2023+
newMarkStyle = (From ms In pDoc.MarkStyles Where ms.Name = newMarkStyleName).ToList.FirstOrDefault

If newMarkStyle Is Nothing Then
	Dim sourceMrkStyle = (From ms In pDoc.MarkStyles Where ms.InternalName = "1:Default" + vbLf).ToList.FirstOrDefault

	logger.info("Local MarkStyles Count-1: " & (From ms In pDoc.MarkStyles Where ms.StyleLocation <> kLibraryStyleLocation).ToList.Count)
		newMarkStyle = sourceMrkStyle.Copy(newMarkStyleName)
	logger.info("Local MarkStyles Count-2: " & (From ms In pDoc.MarkStyles Where ms.StyleLocation <> kLibraryStyleLocation).ToList.Count)
End If

logger.info("pDoc.ActiveMarkStyle-1: " & pDoc.ActiveMarkStyle.Name)
pDoc.ActiveMarkStyle = newMarkStyle
logger.info("pDoc.ActiveMarkStyle-2: " & pDoc.ActiveMarkStyle.Name)

Dim actMrkStyle = pDoc.ActiveMarkStyle
Dim fColor As Color = actMrkStyle.FrontLayerColor

fColor.SetColor(0, 0, 0)

newMarkStyle.FrontLayerColor = fColor ' Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)) ??

MsgBox("Done!")

Works as expected only on second (and consequent) runs.

and I can't debug this with my current knowledge level 😞

Please, help.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 9

MjDeck
Autodesk
Autodesk

Hi Maxim - in Inventor 2025.1.2 with TutorialFile.ipt, I don't see the  80004005 Exception on first run. Can you post a part that shows the error? Or does it only happen on earlier versions of Inventor?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 9

Maxim-CADman77
Advisor
Advisor

That's true - not reproducible in 2025 (my project is for 2024)

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 9

MjDeck
Autodesk
Autodesk

I tested on 2024.3.2 and still get no error. Am I missing some steps? I just open TutorialFile.ipt and run the rule.
Does the error happen for you in the original TutorialFile.ipt?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 7 of 9

Maxim-CADman77
Advisor
Advisor
I can reliably reproduce the Exception with those steps:
1. Download TutorialFile.ipt attached to Message#1
2. Open it with Inventor 2024.3.2
3. Run the rule from Message#3 (as external) 1st time (get the Exception*)
4. Run the rule 2nd time (get no Exception)

*

Error on line 27 in rule: 1, in document: TutorialFile.ipt
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 8 of 9

Maxim-CADman77
Advisor
Advisor

UPDATE:
I can't reproduce the exception on the second PC (neither 2024.3.1 nor 2024.3.2)
Will try to follow corresponding article to troubleshoot/fix Inventor on the first PC and inform about results.

Please vote for Inventor-Idea Text Search within Option Names

Message 9 of 9

Maxim-CADman77
Advisor
Advisor

Inventor reinstall solved this issue (sorry for have disturbed twice)

Please vote for Inventor-Idea Text Search within Option Names