Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

3th party apps VS 2010 Color

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
1345 Views, 8 Replies

3th party apps VS 2010 Color

HI all

This time i really need your help. I am traying change the color of an object. Let me explain please.

1. Select a button that has the next code Autodesk.Navisworks.Api.Application.ActiveDocument.Tool.Value = Autodesk.Navisworks.Api.Tool.Select;
2. I select a object (pipe) and then ...
3. Press the other button to change the color of that object.

I dont have much experience.... please help me. Attached a screenshot.

 

Regards

Sergio Franco.

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

Sergio,

 

  See If This Works

 

 

//Begin Code

using NavAPI = Autodesk.Navisworks.Api;

// m_Color should be the Color Selected example: #FFFFFF
System.Windows.Media.Color m_CompColor =(Color)System.Windows.Media.ColorConverter.ConvertFromString
	(
		m_Color
	);
//
NavAPI.Application.ActiveDocument.Models.OverridePermanentColor
(
NavAPI.Application.ActiveDocument.CurrentSelection.SelectedItems,
	new NavAPI.Color
	(
		Convert.ToDouble(m_CompColor.R) / 255,
		Convert.ToDouble(m_CompColor.G) / 255,
		Convert.ToDouble(m_CompColor.B) / 255
	)
);

//End Code

 

 

Message 3 of 9
Anonymous
in reply to: Anonymous

Sergio,

 

 

 I forgot to add this line of Code at the Very end

 

NavAPI.Application.ActiveDocument.CurrentSelection.Clear();

 

 

Colin

Message 4 of 9
Anonymous
in reply to: Anonymous

KempCE

 

Just one error appears, "m_color does not exist in the current context" for try if this works. Help me please...

 

Regards,

SF

Message 5 of 9
Anonymous
in reply to: Anonymous

Sergio,

 

 

In your picture you showed a Button with a Color that the User Selects to change the color. Change m_Color to that Color Selection

 

Regards,

Colin

Message 6 of 9
Anonymous
in reply to: Anonymous

KemCE

 

the code is..

 

string color = "RED";
            // m_Color should be the Color Selected example: #FFFFFF
            System.Windows.Media.Color m_CompColor = (System.Drawing.Color)System.Windows.Media.ColorConverter.ConvertFromString
                (color
                    
                );
            //
            Autodesk.Navisworks.Api.Application.ActiveDocument.Models.OverridePermanentColor
            (
            Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems,
                new Autodesk.Navisworks.Api.Color
                (
                    Convert.ToDouble(m_CompColor.R) / 255,
                    Convert.ToDouble(m_CompColor.G) / 255,
                    Convert.ToDouble(m_CompColor.B) / 255
                )
            );
            Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.Clear();

 

when i change m_color by color that is "string color  ="RED;".  Appears an error "Cannot implicity convert type"System.Drawing.Color" to "System.Windows.Media.Color" ". Please am i doing something wrong??

 

Regards,

SF

Message 7 of 9
Anonymous
in reply to: Anonymous

Sergio,

 

  you will need the R,G,B Hex Color String.

 

Red = #FF0000

 

 

Regards,

Colin

Message 8 of 9
Anonymous
in reply to: Anonymous

Colin

 

Thanks a lot, again...

 

here is the code

 

 

System.Drawing.Color c = System.Drawing.Color.Red;
            string strcolor = System.Drawing.ColorTranslator.ToHtml(c);
            //Autodesk.Navisworks.Api.Application.ActiveDocument.Models.OverridePermanentColor(IEnumerable<ModelItem>, Autodesk.Navisworks.Api.Color.Red);
            // m_Color should be the Color Selected example: #FFFFFF
            System.Windows.Media.Color m_CompColor = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString
                (strcolor
                    
                );
            //
            Autodesk.Navisworks.Api.Application.ActiveDocument.Models.OverridePermanentColor
            (
            Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems,
                new Autodesk.Navisworks.Api.Color
                (
                    Convert.ToDouble(m_CompColor.R) / 255,
                    Convert.ToDouble(m_CompColor.G) / 255,
                    Convert.ToDouble(m_CompColor.B) / 255
                )
            );
            Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.Clear();

 

 

Regards,

 

SF

Message 9 of 9
Anonymous
in reply to: Anonymous

Colin

I am very grateful for your help. Please could you help me with the next.
I am trying to use the function "HIDE UNSELECTED" from my app. I try with the next...


        private void button14_Click(object sender, EventArgs e)
        {
       Autodesk.Navisworks.Api.Application.ActiveDocument.Models.SetHidden(Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems, true);
            Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.Clear();
        }
 

but the result is other. How can i do it??

Please Help.

 
Best Regards,

SF

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report