Navisworks API

Reply
Active Member
SergioFA
Posts: 10
Registered: ‎12-29-2011
Message 1 of 9 (358 Views)
Accepted Solution

3th party apps VS 2010 Color

358 Views, 8 Replies
01-04-2012 08:48 PM

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.

Contributor
KempCE
Posts: 18
Registered: ‎08-02-2011
Message 2 of 9 (350 Views)

Re: 3th party apps VS 2010 Color

01-05-2012 06:13 AM in reply to: SergioFA

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

 

 

Contributor
KempCE
Posts: 18
Registered: ‎08-02-2011
Message 3 of 9 (344 Views)

Re: 3th party apps VS 2010 Color

01-05-2012 08:34 AM in reply to: KempCE

Sergio,

 

 

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

 

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

 

 

Colin

Active Member
SergioFA
Posts: 10
Registered: ‎12-29-2011
Message 4 of 9 (339 Views)

Re: 3th party apps VS 2010 Color

01-05-2012 08:48 AM in reply to: KempCE

KempCE

 

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

 

Regards,

SF

Contributor
KempCE
Posts: 18
Registered: ‎08-02-2011
Message 5 of 9 (337 Views)

Re: 3th party apps VS 2010 Color

01-05-2012 08:50 AM in reply to: SergioFA

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

Active Member
SergioFA
Posts: 10
Registered: ‎12-29-2011
Message 6 of 9 (331 Views)

Re: 3th party apps VS 2010 Color

01-05-2012 10:07 AM in reply to: KempCE

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

Contributor
KempCE
Posts: 18
Registered: ‎08-02-2011
Message 7 of 9 (329 Views)

Re: 3th party apps VS 2010 Color

01-05-2012 10:48 AM in reply to: SergioFA

Sergio,

 

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

 

Red = #FF0000

 

 

Regards,

Colin

Active Member
SergioFA
Posts: 10
Registered: ‎12-29-2011
Message 8 of 9 (322 Views)

Re: 3th party apps VS 2010 Color

01-05-2012 07:00 PM in reply to: SergioFA

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

Active Member
SergioFA
Posts: 10
Registered: ‎12-29-2011
Message 9 of 9 (305 Views)

Re: 3th party apps VS 2010 Color

01-09-2012 10:52 AM in reply to: SergioFA

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community