Set HalfTone

Set HalfTone

jainn
Advocate Advocate
1,976 Views
5 Replies
Message 1 of 6

Set HalfTone

jainn
Advocate
Advocate

Hi,  

 

How to set HalfTone Programatically.  

Please suggest  

 

Regards Namit

Accepted solutions (1)
1,977 Views
5 Replies
Replies (5)
Message 2 of 6

rosalesduquej
Alumni
Alumni
Accepted solution

Hi Namit,

 

Have you checked out the Revit Help file? If you look for Halftone, one of the first results is SetHalfTone method.

 

OverrideGraphicSettings.SetHalftone Method which will help you to set the HalfTone value.

 

http://revitapisearch.com/html/1e379671-3cb3-7368-9208-d113ea1c4c09.htm

 

Cheers,



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
0 Likes
Message 3 of 6

Anonymous
Not applicable

I'm fairly new to C#. I'm also trying to create a command to make an element halftone in view.  I want it to first test whether the element is halftone and then switch states so I can use the command to flip-flop the element's halftone display.  I think I've incorporated the Halftone { get; } correctly to do this.

 

I have successfully gotten the command to make an element halftone, but I cannot yet get it to change that same element back again.

0 Likes
Message 4 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

hi @Anonymous,

Try using the below code

ElementId eid;
if(doc.ActiveView.GetElementOverrides(eid).Halftone==true)
                   {
                        OverrideGraphicSettings ORGS = new OverrideGraphicSettings();
                        ORGS.SetHalftone(false);
                        doc.ActiveView.SetElementOverrides(eid, ORGS);
                   }
                   else if (doc.ActiveView.GetElementOverrides(eid).Halftone == false)
                   {
                        OverrideGraphicSettings ORGS = new OverrideGraphicSettings();
                        ORGS.SetHalftone(true);
                        doc.ActiveView.SetElementOverrides(eid, ORGS);
                   }

If this helped solve your problem please mark it as solution, so other users can get this solutions as wellSmiley Happy


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 5 of 6

stever66
Advisor
Advisor

That works very well Naveen.

 

I don't want to hijack this thread, but is there a simple way to add to this to set the Projection Line Color and Pattern?

 

For the Projection Line Color, it looks like I need to add:

 

ORGS.SetProjectionLineColor(Color color);

 

But I don't have enough C# experience to know what to put in the parenthesis.  I have a similar issue with the line pattern.  I'm not sure how to specify it by name.

 

Thanks,

Steve

 

 

0 Likes
Message 6 of 6

stever66
Advisor
Advisor

I have tried this before with no luck, but with some more internet searching, and some trial and error, I've managed to answer my own question.


To set the color one can use something like this:


Color black = new Color(0x000x000x00);

Color blue = new Color(0x000x000xFF);

ORGS.SetProjectionLineColor(blue);

 

or:

ORGS.SetProjectionLineColor(new Color(0x00, 0x00, 0xFF));

 

Setting the lineweight is pretty easy:

ORGS.SetProjectionLineWeight(5);

 

Setting the pattern was a little harder since I had to find the line pattern with a filtered element collector.  But I found one of Jeremy's examples:

 

FilteredElementCollector fec = new FilteredElementCollector( doc ).OfClasstypeof( LinePatternElement ) );

 LinePatternElement linePatternElem = fec.Cast<LinePatternElement>().First<LinePatternElement>( linePattern => linePattern.Name == "long dash");  

 

ORGS.SetProjectionLinePatternId(linePatternElem.Id);

 

I also wanted to find a line pattern called Center 1/4", and including the quote was a little more difficult.  But following by example I found this would work with 3 quotes on the end:

 

 linePattern.Name == @"Center 1/4"""

 

                 

0 Likes