Colour Face Of A-Side In Specific ViewRep C#

Colour Face Of A-Side In Specific ViewRep C#

bruce.blundell
Participant Participant
474 Views
3 Replies
Message 1 of 4

Colour Face Of A-Side In Specific ViewRep C#

bruce.blundell
Participant
Participant

Hi All,

 

I am looking to Set the color of the A-Side face to a specific color

but only do it in a specific view rep

my code is in C# but happy to translate from Vb 

 

I am able to set the view rep no problem

 public void PrtCreateVRep(string nViewRep)
        {
            Connect(out Inventor.Application m_InvApp, out bool InvActive);

            TestPart(out bool oPartTest);
            if (oPartTest == true)
            {

                //Active Part Document
                PartDocument oPartDoc = (PartDocument)m_InvApp.ActiveDocument;

                //Define Component definition
                PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition;

                //get Manager of Representations
                RepresentationsManager dViewRepMgr = oCompDef.RepresentationsManager;

                //get active Representation view
                DesignViewRepresentation dViewRep = dViewRepMgr.ActiveDesignViewRepresentation;

                DesignViewRepresentations oDesignViewReps = oCompDef.RepresentationsManager.DesignViewRepresentations;

                //DesignViewRepresentation oDesignViewRep = default(DesignViewRepresentation);
                int dViewRepCounts = oDesignViewReps.Count;

                if (nViewRep != "")
                {
                    try
                    {
                        oDesignViewReps[nViewRep].Activate();
                        //Inventor Status Bar Feedback
                        m_InvApp.StatusBarText = "View Representation: " + "'" + nViewRep + "'" + " Exists. " + "'" + nViewRep + "'" + " View Representation Now Activaded.";
                    }
                    catch
                    {
                        DesignViewRepresentation oDesignViewRep = default(DesignViewRepresentation);
                        oDesignViewRep = oDesignViewReps.Add(nViewRep);

                        oDesignViewReps[nViewRep].Activate();

                        //Inventor Status Bar Feedback
                        m_InvApp.StatusBarText = "View Representation: " + "'" + nViewRep + "'" + " Created. " + "'" + nViewRep + "'" + " View Representation Now Activaded.";

                    }
                }
                else
                {
                    MessageBox.Show("No View Rep Name Selected!", "UAPTools");

                }

            }

            else
            {
                MessageBox.Show("Please Activate a Valid Part Document", "UAPTools");
            }


        }

Then set the face to the Color

 public void SetA_SideColour(string oColour)
        {

            Connect(out Inventor.Application m_InvApp);

            InvPart constrClass = new InvPart();
            constrClass.TestPart(out bool oPartTest);

            if (oPartTest == true)
            {

                //Active Part Document
                PartDocument oPartDoc = (PartDocument)m_InvApp.ActiveDocument;

                //Define Component definition
                //PartComponentDefinition oCompDef = oPartDoc.ComponentDefinition;

                SMCheck(out bool oSMTest);

                if (oSMTest == true)
                {

                    SheetMetalComponentDefinition oSMCompDef = (SheetMetalComponentDefinition)oPartDoc.ComponentDefinition;

                    if (oSMCompDef.ASideFaceStatus == ASideFaceStatusEnum.kASideUpToDate)
                    {

                        ASideDefinition oAsideDef = oSMCompDef.ASideDefinitions[1];

                        Face oFace = oAsideDef.Faces[1];

                        //Face oFace = oAside.Faces[1];

                        if (oColour != "")
                        {
                            if (oColour == "As Feature")
                            {
                                try
                                {
                                    //Set Enum
                                    StyleSourceTypeEnum oStyle = StyleSourceTypeEnum.kFeatureRenderStyle;

                                    //Set Render Style of faces
                                    oFace.SetRenderStyle(oStyle);

                                }
                                catch
                                {
                                    //Inventor Status Bar Feedback
                                    m_InvApp.StatusBarText = "RenderStyle/Appearance : " + "' " + oColour + " '" + " Could Not Be activated";
                                }
                            }
                            else
                            {

                                try
                                {
                                    RenderStyle oRenderStyle = oPartDoc.RenderStyles[oColour];

                                    //Set Enum
                                    StyleSourceTypeEnum oStyle = StyleSourceTypeEnum.kOverrideRenderStyle;

                                    //Set Render Style of faces
                                    oFace.SetRenderStyle(oStyle, oRenderStyle);

                                }
                                catch
                                {
                                    //Inventor Status Bar Feedback
                                    m_InvApp.StatusBarText = "RenderStyle/Appearance : " + "' " + oColour + " '" + " Could Not Be activated";
                                }
                            }

                        }
                    }
                    else
                    {

                    }

                    m_InvApp.ActiveView.Update();

                }
            }


        }

But This overrides the color in all view reps

 

Any thoughts?

 

0 Likes
475 Views
3 Replies
Replies (3)
Message 2 of 4

bruce.blundell
Participant
Participant

@NachoShaw  any ideas?

0 Likes
Message 3 of 4

JMGunnar
Collaborator
Collaborator

Designviews in Parts not support different Face colour 

 

 

Inventor Ideas

https://forums.autodesk.com/t5/inventor-ideas/idb-p/v1232

0 Likes
Message 4 of 4

NachoShaw
Advisor
Advisor

We could add a condition based on a view rep and call the function on a documentEvent. The color, face name & viewrep name could be saved as attributes along with the face name

 

Change ViewRep

initiate DocumentEvent

check thata ViewRep has changed and get its name

If ViewRep Name = Attribute ViewRep name

Select face by Attribute name

assign Attribute color to it

 

you can save attributes to a face so each face can hold its own attribute colors and then be collected when the face is selected

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes