How to change the color of a dimension object in an overrule object?

How to change the color of a dimension object in an overrule object?

fadics
Participant Participant
1,058 Views
12 Replies
Message 1 of 13

How to change the color of a dimension object in an overrule object?

fadics
Participant
Participant

I created an overrule object to change a Point object to a group of objects. The color of these objects can be changed by below code in WorldDraw function of the overrule object. But the Dimension objects' color can't be changed this way. How to change it?

Thanks!

 

public override bool WorldDraw(Drawable drawable, WorldDraw wd)

{

...

short oldColor = wd.SubEntityTraits.Color;

wd.SubEntityTraits.Color = 1;

entities[i].WorldDraw(wd);

wd.SubEntityTraits.Color = oldColor;

...

}

0 Likes
Accepted solutions (1)
1,059 Views
12 Replies
Replies (12)
Message 2 of 13

ActivistInvestor
Mentor
Mentor

You're not showing enough code to give you a intelligent answer.

 

0 Likes
Message 3 of 13

fadics
Participant
Participant

ok. I'll provide more code.

0 Likes
Message 4 of 13

fadics
Participant
Participant

Attached file is a solution to illustrate my question.

Steps:

1. NETLOAD my solution compiling result dll.

2. LINETYPE to add "BATTING" line type.

3. POINT to add a point.

4. Run my command TESTOVERRULE of the solution.

Now, you can find that the point is changed to several Texts, Lines and Dimensions. The color of Texts and Lines is different. But the color of the Dimensions is same. My question is how to change the color of the Dimensions.

0 Likes
Message 5 of 13

ActivistInvestor
Mentor
Mentor

Sorry, I don't have time to build and debug your code.

 

It has numerous problems, starting with the use of a Transaction inside of a DrawableOverrule's WorldDraw() method. That is simply not going to work. You should use an OpenCloseTransaction in that situation.

 

You are also creating dozens of new DBObjects/Entities and not disposing them or adding them to a Database, which will eventually cause AutoCAD to crash (it doesn't happen until the garbage collector finalizes those objects). The problem with not being able to control the color of dimensions is most-likely because the dimensions are not in a Database, but that is only my guess.

 

 

0 Likes
Message 6 of 13

fadics
Participant
Participant

Why a Transaction is not going to work inside of a DrawableOverrule's WorldDraw()? Actually, it works as expected. The correct LineType id is gotten and applied.

Why an OpenCloseTransaction is needed here? To open the current database again?

 

Thanks to remind the Dispose issue. I failed to copy it together from the actual code.

 

The color can be controlled if there is a Dimension saved in the database. But another two problem arise. The first is, a redundant Dimension exists in the drawing. A redundant Dimension is not acceptable for our customers. The second is, the Dimension drawn in the Overrule object can't be moved to the correct position. I tried to copy an entity for drawing. The color can't be applied again.

 

I think my example code had made our request clear. I want to Overrule a point to a combination of lines, texts and dimensions. The color and text alignment mode should be specified not default. Would you please just show me a simple example of how to specify the color of a dimension and the text alignment mode of a text entity?

Thanks!

0 Likes
Message 7 of 13

ActivistInvestor
Mentor
Mentor

@fadics wrote:

Why a Transaction is not going to work inside of a DrawableOverrule's WorldDraw()? Actually, it works as expected. 

It doesn't work. You are confusing not testing it with believing it works because the objects are drawn as expected when you issue the REGEN command.

 

WorldDraw() can be called in many different situations, not only within the REGEN command. In most of those situations, using a regular Transaction will corrupt UNDO and REDO, and often has the result of disabling REDO.

 

So, You think it works when you use REGEN and the outcome is what you expected, and that's because you haven't really tested the code in every possible context or scenario in which it can execute, and have no understanding of how it will corrupt UNDO and/or REDO.

 

The reason that OpenCloseTransaction exists in the first place, is so that using a regular Transaction can be avoided when its use interferes with UNDO and REDO as well as other operations, all of which I don't have time to get into.

 

Since you seem to have yourself convinced that you know what you're doing and can't be told otherwise, this is where I get off.

 

 

0 Likes
Message 8 of 13

fadics
Participant
Participant

Thanks to clarify the difference of Transaction and OpenCloseTransaction!

0 Likes
Message 9 of 13

1742647821
Participant
Participant

if you want to change the color of display by overrule, you need to override SetAttribute method

0 Likes
Message 10 of 13

fadics
Participant
Participant

@1742647821 I want to overrule a point to a dimension and change the color of the dimension. It seems SetAttribute can only change the color of the point not the dimension.

0 Likes
Message 11 of 13

1742647821
Participant
Participant

oh sorry, you are right, so why not change the ColorIndex of dim?

0 Likes
Message 12 of 13

fadics
Participant
Participant

I changed the colorindex of the dimension. It didn't work. The color is still white which is neither the color I set to Dimension.ColorIndex nor the color I set to WorldDraw.SubEntityTraits.Color. I don't know where to change it.

0 Likes
Message 13 of 13

fadics
Participant
Participant
Accepted solution

I figured out a solution for this issue:

Create a dimension at the same place and layer.

Set the dimension to invisible.

Draw the dimension at the WorldDraw function in a DrawableOverrule class.

Change the position of the dimension at the TransformBy function in a TransformOverrule class or destroy and recreate the dimension at the new position.

0 Likes