Ejemplo n.º 1
0
        private void ExportNode(ComponentOccurrence componentOccurrence, SceneBuilder scene, NodeBuilder node)
        {
            var componentOccurrenceDefinition = componentOccurrence.Definition;

            if (includeSynthData)
            {
                var occurrencePath = GetOccurrencePath(componentOccurrence);
                node.Name = occurrencePath;
                allComponentRealNames[occurrencePath] = componentOccurrence.Name;
            }
            else
            {
                node.Name = componentOccurrence.Name;
            }


            // ExportAppearanceCached(componentOccurrence.Appearance);

            // node.LocalTransform = InvToGltfMatrix4X4(componentOccurrence.Transformation); TODO: mesh caching by using definitions instead of occurrences (materials were an issue)
            switch (componentOccurrenceDefinition.Type)
            {
            case ObjectTypeEnum.kAssemblyComponentDefinitionObject:
                ExportNodeAssembly(componentOccurrence, scene, node);
                break;

            case ObjectTypeEnum.kPartComponentDefinitionObject:
                ExportNodePart(componentOccurrence, scene, node);
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the supplied component as a node with its corresponding parents and children.
        /// </summary>
        /// <param name="component"></param>
        public void AddComponent(ComponentOccurrence component)
        {
            if (!component.Visible)
            {
                return;
            }

            TreeNode node = new TreeNode(component.Name);

            node.Name = node.Text;
            node.Tag  = component;

            node = GenerateFullTree(component, node);

            TreeNodeCollection iterator = Nodes;

            while (iterator.ContainsKey(node.Name) && node.Nodes.Count == 1)
            {
                iterator = iterator[iterator.IndexOfKey(node.Name)].Nodes;
                node     = node.Nodes[0];
            }

            iterator.RemoveByKey(node.Name);
            iterator.Add(node);
        }
Ejemplo n.º 3
0
        public void getForm()
        {
            int  offsetY = 30, offsetX = 10;
            Form f = new Form();

            f.Height       = 150; f.Width = 400; f.WindowState = FormWindowState.Normal; f.Text = "Смещение"; f.StartPosition = FormStartPosition.CenterScreen;
            f.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; f.AutoSize = true;
            System.Drawing.Point insPt = new System.Drawing.Point(5, 5);
            InterfaceDll.Lbl     lbs   = new Lbl(offsetX, offsetY, 100, 15, insPt, f, "Дистанция");
            InterfaceDll.CB      cbs   = new CB(offsetX, offsetY, 200, 15, insPt, f);
            cbs.position(lbs.last(), true);
            //cbs.last().Items.AddRange(new[] { "2.65", "2.8", "3", "4.5", "6" });
            ComponentOccurrence occ = ss[1] as ComponentOccurrence;

            if (occ == null)
            {
                return;
            }
            ins = occ.Constraints[1] as InsertConstraint;
            if (ins == null)
            {
                return;
            }


            cbs.last().Text       = last(ins.Distance);
            InterfaceDll.Btn btns = new Btn(offsetX, offsetY, 100, 20, insPt, f, click, "Добавить");
            btns.center(cbs.last(), offsetY + 5);
            f.Show();
        }
Ejemplo n.º 4
0
        public double[] FindOrigin(ComponentOccurrence oCompOccur)
        {
            UnitsOfMeasure oUOM = _invApp.ActiveDocument.UnitsOfMeasure;
            AssemblyComponentDefinition oCompDef = (AssemblyComponentDefinition)oCompOccur.Definition;
            object oWorkPointProxy;

            double[]  c   = new double[3];
            WorkPoint oWP = oCompDef.WorkPoints[1];

            oCompOccur.CreateGeometryProxy(oWP, out oWorkPointProxy);

            c[0] = ((WorkPointProxy)oWorkPointProxy).Point.X;
            c[1] = ((WorkPointProxy)oWorkPointProxy).Point.Y;
            c[2] = ((WorkPointProxy)oWorkPointProxy).Point.Z;

            for (int k = 0; k < 3; k++)
            {
                c[k] = oUOM.ConvertUnits(c[k], "cm", "m");
            }

            string AbsolutePosition, name;

            name = FormatName(oCompOccur.Name);

            return(c);
        }
Ejemplo n.º 5
0
 private void AddCasingComponentRecursive(ComponentOccurrence occurrence, Component component)
 {
     try
     {
         if (occurrence.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
         {
             AssemblyDocument assembly     = (AssemblyDocument)occurrence.Definition.Document;
             Component        subComponent = GetCasingComponent(assembly);
             // check whether the component exists
             bool hasComponent = false;
             foreach (Component componentLoc in component.Components)
             {
                 if (componentLoc.FullFileName == subComponent.FullFileName)
                 {
                     hasComponent = true;
                 }
             }
             if (!hasComponent)
             {
                 component.Components.Add(subComponent);
             }
             // Recursive call
             //foreach (ComponentOccurrence subOccurrence in assembly.ComponentDefinition.Occurrences)
             //{
             //	AddCasingComponentRecursive(subOccurrence, subComponent);
             //}
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK);
     }
 }
Ejemplo n.º 6
0
        public static List <ComponentOccurrence> GetComponentOccurrencesFromNodes(List <RigidNode_Base> nodes)
        {
            if (nodes == null)
            {
                return(null);
            }

            // Get all node ID's
            List <string> nodeIDs = new List <string>();

            ;
            foreach (RigidNode_Base node in nodes)
            {
                nodeIDs.AddRange(node.GetModelID().Split(new String[] { "-_-" }, StringSplitOptions.RemoveEmptyEntries));
            }

            // Select all nodes
            List <ComponentOccurrence> occurrences = new List <ComponentOccurrence>();

            foreach (string id in nodeIDs)
            {
                ComponentOccurrence occurrence = GetOccurrence(id);

                if (occurrence != null)
                {
                    occurrences.Add(occurrence);
                }
            }

            return(occurrences);
        }
Ejemplo n.º 7
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (_invApp.Documents.Count == 0)
            {
                MessageBox.Show("Need to open an Assembly document");
                return;
            }

            if (_invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject)
            {
                MessageBox.Show("Need to have an Assembly document active");
                return;
            }

            AssemblyDocument asmDoc = (AssemblyDocument)_invApp.ActiveDocument;
            // Get the attribute manager for the document
            AttributeManager attbMan = asmDoc.AttributeManager;

            // Find the objects with the attributes
            ObjectCollection objCol = default(ObjectCollection);

            objCol = attbMan.FindObjects("myPartGroup", "PartGroup1", "Group1");

            AttributeSets attbSets = default(AttributeSets);

            // Delete the attribute from the ComponentOccurrence
            foreach (object obj in objCol)
            {
                ComponentOccurrence compOcc = (ComponentOccurrence)obj;
                attbSets = compOcc.AttributeSets;
                attbSets["myPartGroup"].Delete();
                // Make the ComponentOccurrence visible
                compOcc.Visible = true;
            }
        }
Ejemplo n.º 8
0
        private BrowserFolder getFolderForFile(BrowserPane browserPane, string searchedFileName)
        {
            BrowserFolder folder = null;

            foreach (BrowserFolder curentFolder in browserPane.TopNode.BrowserFolders)
            {
                foreach (BrowserNode node in curentFolder.BrowserNode.BrowserNodes)
                {
                    if (node.NativeObject is ComponentOccurrence)
                    {
                        ComponentOccurrence occ = (ComponentOccurrence)node.NativeObject;
                        string currentFileName  = occ.ReferencedFileDescriptor.FullFileName;
                        if (!searchedFileName.Equals(currentFileName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                    folder = curentFolder;
                    break;
                }
            }

            if (folder == null)
            {
                ObjectCollection colNodes = inventor.TransientObjects.CreateObjectCollection();
                folder = browserPane.AddBrowserFolder("temp", colNodes);
            }

            return(folder);
        }
Ejemplo n.º 9
0
        private MeshBuilder <VertexPositionNormal> ExportMesh(ComponentOccurrence componentOccurrence)
        {
            var occurrencePath = GetOccurrencePath(componentOccurrence);
            var mesh           = new MeshBuilder <VertexPositionNormal>(occurrencePath);

            if (includeSynthData)
            {
                try
                {
                    massPropertiesMap[occurrencePath] = componentOccurrence.MassProperties;
                }
                catch { }
            }

            foreach (SurfaceBody surfaceBody in componentOccurrence.SurfaceBodies)
            {
                if (exportMaterials && exportFaceMaterials)
                {
                    var surfaceBodyFaces = surfaceBody.Faces;
                    foreach (Face face in surfaceBodyFaces)
                    {
                        ExportPrimitive(face, mesh.UsePrimitive(ExportAppearanceCached(face.Appearance)));
                    }
                }
                else
                {
                    ExportPrimitive(surfaceBody, mesh.UsePrimitive(ExportAppearanceCached(componentOccurrence.Appearance)));
                }
            }

            return(mesh);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a component to the Component Property Dictionary.
        /// </summary>
        /// <param name="ComponentID"></param>
        /// <param name="Component"></param>
        public static void AddComponents(string ComponentID, ComponentOccurrence Component)
        {
            switch (Component.DefinitionDocumentType)
            {
            case DocumentTypeEnum.kPartDocumentObject:
                CompPropertyDictionary.Add(Component.Name, ComponentID);
                break;

            case DocumentTypeEnum.kAssemblyDocumentObject:
                AssemblyComponentDefinition AsmDef = (AssemblyComponentDefinition)Component.Definition;
                List <string> AssemblyPartList     = new List <string>();
                foreach (ComponentOccurrence Comp in AsmDef.Occurrences.AllLeafOccurrences)
                {
                    try
                    {
                        AssemblyPartList.Add(Comp.Name);
                        CompPropertyDictionary.Add(Comp.Name, ComponentID);
                    }
                    catch (ArgumentException) { }
                }
                try
                {
                    AssemblyDictionary.Add(Component.Name, AssemblyPartList);
                }
                catch (ArgumentException)
                {
                    AssemblyDictionary.Remove(Component.Name);
                    AssemblyDictionary.Add(Component.Name, AssemblyPartList);
                }
                break;

            default:
                throw new ArgumentException("ERROR: Component not an assembly or part", "Component");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds parent and child components to the given node and returns the root node.
        /// </summary>
        /// <param name="component"></param>
        /// <param name="node"></param>
        /// <returns>The node</returns>
        private TreeNode GenerateFullTree(ComponentOccurrence component, TreeNode node)
        {
            node = AddComponentChildren(component, node);
            node = AddComponentParents(component, node);
            node = FindRootNode(node);

            return(node);
        }
Ejemplo n.º 12
0
            public ListViewItemTag(
                ComponentOccurrence occurrence,
                TreeNode treeNode)
            {
                Occurrences = new List <ComponentOccurrence>();
                Occurrences.Add(occurrence);

                TreeNode = treeNode;
            }
Ejemplo n.º 13
0
            public TreeNodeTag(
                ComponentOccurrence occurrence,
                ListViewItem listViewItem)
            {
                Occurrences = new List <ComponentOccurrence>();
                Occurrences.Add(occurrence);

                ListViewItem = listViewItem;
            }
Ejemplo n.º 14
0
        private void onClickBundle(NameValueMap Context)
        {
            Document oDoc = inventor.ActiveDocument;

            if (!(oDoc is AssemblyDocument))
            {
                return;
            }

            AssemblyDocument doc         = (AssemblyDocument)oDoc;
            BrowserPane      browserPane = doc.BrowserPanes[MODELBROWSERNAME];
            BrowserNode      topNode     = browserPane.TopNode;

            BrowserNode selectedNode = getSelectedNode(topNode);

            if (selectedNode == null)
            {
                return;
            }

            string fileToBundle = "";

            if (selectedNode.NativeObject is ComponentOccurrence)
            {
                ComponentOccurrence occ = (ComponentOccurrence)selectedNode.NativeObject;
                fileToBundle = occ.ReferencedFileDescriptor.FullFileName;

                BrowserFolder folder = getFolderForFile(browserPane, fileToBundle);

                List <BrowserNode> nodesWithFileName = getNodesWithFileName(fileToBundle, topNode);
                foreach (BrowserNode foundNode in nodesWithFileName)
                {
                    folder.Add(foundNode);
                }
                folder.Name = nodesWithFileName.Count + "x " + System.IO.Path.GetFileNameWithoutExtension(fileToBundle);
            }
            else if (selectedNode.NativeObject is BrowserFolder)
            {
                BrowserFolder folder = (BrowserFolder)selectedNode.NativeObject;

                if (folder.BrowserNode.BrowserNodes[1].NativeObject is ComponentOccurrence)
                {
                    ComponentOccurrence occ = (ComponentOccurrence)folder.BrowserNode.BrowserNodes[1].NativeObject;
                    fileToBundle = occ.ReferencedFileDescriptor.FullFileName;

                    folder.Delete();
                    folder = getFolderForFile(browserPane, fileToBundle);

                    List <BrowserNode> nodesWithFileName = getNodesWithFileName(fileToBundle, topNode);
                    foreach (BrowserNode foundNode in nodesWithFileName)
                    {
                        folder.Add(foundNode);
                    }
                    folder.Name = nodesWithFileName.Count + "x " + System.IO.Path.GetFileNameWithoutExtension(fileToBundle);
                }
            }
        }
Ejemplo n.º 15
0
 public void offset(ComponentOccurrence occ, double d = 20)
 {
     ins = occ.Constraints[1] as InsertConstraint;
     if (ins == null)
     {
         return;
     }
     str(ins.Distance, d);
 }
Ejemplo n.º 16
0
 public static ComponentOccurrence GetParent(ComponentOccurrence cO)
 {
     if (cO.ParentOccurrence != null)
     {
         return(GetParent(cO.ParentOccurrence));
     }
     else
     {
         return(cO);
     }
 }
Ejemplo n.º 17
0
 public string ReturnParentName(ComponentOccurrence occur)
 {
     try
     {
         return(occur.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("Parent").Value);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(null);
     }
 }
Ejemplo n.º 18
0
    /// <summary>
    /// Exports from a ComponentOccurrence.
    /// </summary>
    /// <param name="component"></param>
    /// <param name="bestResolution"></param>
    /// <param name="separateFaces"></param>
    /// <param name="ignorePhysics"></param>
    public void Export(ComponentOccurrence component, bool bestResolution = false,
                       bool separateFaces = false, bool ignorePhysics = false)
    {
        List <ExportPlan> plans = new List <ExportPlan>();

        plans.AddRange(GenerateExportList(component, bestResolution, separateFaces, ignorePhysics));

        for (int i = 0; i < plans.Count; i++)
        {
            AddFacets(plans[i].surf, plans[i].bestResolution, plans[i].separateFaces);
        }
    }
Ejemplo n.º 19
0
        public double[] ComputeRelativeOffset(ComponentOccurrence Child, ComponentOccurrence Parent)
        {
            double[] c1 = FindOrigin(Parent);
            double[] c2 = FindOrigin(Child);
            double[] c3 = new double[3];

            for (int k = 0; k < 3; k++)
            {
                c3[k] = c2[k] - c1[k];
            }

            return(c3);
        }
        /// <summary>
        /// Gets the status of component in the assembly
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public bool GetComponentStatus(string name)
        {
            try
            {
                ComponentOccurrence occ = _adoc._adef.Occurrences.ItemByName[name];

                return(occ.Suppressed);
            }
            catch
            {
                throw new Exception("Could not find component " + name);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Get the occurence path as a list of strings
        /// </summary>
        /// <param name="occurrence"></param>
        /// <returns></returns>
        public static List <string> GetOccurencePath(this ComponentOccurrence occurrence)
        {
            var tempList = new List <string>();

            if (occurrence != null)
            {
                foreach (ComponentOccurrence c in occurrence.OccurrencePath)
                {
                    tempList.Add(c.Name);
                }
            }

            return(tempList);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets the occurence path as large string
        /// </summary>
        /// <param name="occurrence"></param>
        /// <returns></returns>
        public static string GetOccurencePathString(this ComponentOccurrence occurrence)
        {
            string temp = "";

            if (occurrence != null)
            {
                foreach (ComponentOccurrence c in occurrence.OccurrencePath)
                {
                    temp += c.Name;
                }
            }

            return(temp);
        }
Ejemplo n.º 23
0
 //Main form Buttons
 #region Buttons
 //ok button
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         var_es.part_doc.SaveAs(path + @"/Shaft.ipt", true);
         TransientGeometry   TG     = var_es.InventorApp.TransientGeometry;
         Matrix              matrix = TG.CreateMatrix();
         ComponentOccurrence Shaft1 = var_es._Doc.ComponentDefinition.Occurrences.Add(path + @"/Shaft.ipt", matrix);
         //ComponentOccurrence Shaft = var_es._Doc.ComponentDefinition.Occurrences.Add(path + @"/Shaft.iam", matrix);
         var_es.part_doc.Close(true);
         Close();
     }
     catch { }
 }
Ejemplo n.º 24
0
        public InstanceData(
            ComponentOccurrence occ, int index)
        {
            // Could be assembly or part, but their relevant
              // properties are the same, so can use "dynamic"
              dynamic doc = occ.Definition.Document;

              AssemblyDocument asm = occ.ContextDefinition.Document as AssemblyDocument;

              // occurrences have no unique ID, only documents have
              // let's create it based on the top assembly doc ID + component index
              string internalName = asm.InternalName + "-" + index.ToString(); // Returns GUID + index
              Debug.Print(internalName);

              Vector pos = occ.Transformation.Translation;
              string jsonProps = Util.GetPropertiesJson( );

              // /a/src/web/CompHoundWeb/model/instance.js
              // _id        : UniqueId // suppress automatic generation
              // project    : String
              // path       : String
              // urn        : String
              // family     : String
              // symbol     : String
              // category   : String
              // level      : String
              // x          : Number
              // y          : Number
              // z          : Number
              // easting    : Number // Geo2d?
              // northing   : Number
              // properties : String // json dictionary of instance properties and values

              _id = internalName;
              project = asm.DisplayName; // Assembly doc name
              path = asm.File.FullFileName; // Assembly doc path
              urn = string.Empty;
              family = doc.DisplayName;
              symbol = occ.Name; // Component occurrence name?
              category = "";
              level = "-1";
              x = Util.ConvertCmToMillimetres( pos.X );
              y = Util.ConvertCmToMillimetres( pos.Y );
              z = Util.ConvertCmToMillimetres( pos.Z );
              easting = 0;
              northing = 0;
              properties = jsonProps;
        }
Ejemplo n.º 25
0
        private void insertPartsAndMateEdges()
        {
            // create an assembly
            AssemblyDocument            oAssDoc = (AssemblyDocument)mApp.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject);
            AssemblyComponentDefinition oAssDef = oAssDoc.ComponentDefinition;

            Matrix oM = mApp.TransientGeometry.CreateMatrix();

            //place the two parts
            ComponentOccurrence oOcc1 = oAssDef.Occurrences.Add("c:\\temp\\test1.ipt", oM);
            ComponentOccurrence oOcc2 = oAssDef.Occurrences.Add("c:\\temp\\test2.ipt", oM);

            // find the two faces to mate
            PartDocument     oDoc1          = (PartDocument)oOcc1.Definition.Document;
            ObjectCollection oObjCollection = oDoc1.AttributeManager.FindObjects("demoAttset", "demoAtt");

            Face oFace1 = null;

            if (oObjCollection[1] is Face)
            {
                oFace1 = (Face)oObjCollection[1];
            }

            PartDocument oDoc2 = (PartDocument)oOcc2.Definition.Document;

            oObjCollection = oDoc2.AttributeManager.FindObjects("demoAttset", "demoAtt");

            Face oFace2 = null;

            if (oObjCollection[1] is Face)
            {
                oFace2 = (Face)oObjCollection[1];
            }

            Object tempObj;

            //create the proxy objects for the two faces

            oOcc1.CreateGeometryProxy(oFace1, out tempObj);
            FaceProxy oAsmProxyFace1 = (FaceProxy)tempObj;

            oOcc2.CreateGeometryProxy(oFace2, out tempObj);
            FaceProxy oAsmProxyFace2 = (FaceProxy)tempObj;

            // add the mate constraint
            oAssDef.Constraints.AddMateConstraint(oAsmProxyFace1, oAsmProxyFace2, 0);
        }
Ejemplo n.º 26
0
        private void ExportNodeAssembly(ComponentOccurrence componentOccurrence, SceneBuilder scene, NodeBuilder node)
        {
            // ReSharper disable once SuspiciousTypeConversion.Global
            var assemblyComponentDefinition = (AssemblyComponentDefinition)componentOccurrence.Definition;

            try
            {
                if (visitedDocuments.Add(assemblyComponentDefinition.Document.InternalName()))
                {
                    progressBar.Message = "Exporting mesh " + visitedDocuments.Count + " of " + progressTotal + "...";
                    progressBar.UpdateProgress();
                }
            }
            catch { }

            ExportNodes(componentOccurrence.SubOccurrences.Cast <ComponentOccurrence>(), scene, node);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static bool FindParentFeature(AssemblyDocument ParentDocument,
                                             PartFeature partFeature,
                                             out PartFeature asmFeature,
                                             out ComponentOccurrence occurrence)
        {
            asmFeature = null;
            occurrence = null;

            try
            {
                AttributeSet set = partFeature.AttributeSets[_AttributeSet];

                Byte[] contextData = set["ContextData"].Value as Byte[];

                int keyContext = ParentDocument.ReferenceKeyManager.LoadContextFromArray(ref contextData);


                Byte[] refKey1 = set["AsmFeatureRefKey"].Value as Byte[];

                object MatchType1;

                asmFeature = ParentDocument.ReferenceKeyManager.BindKeyToObject(ref refKey1,
                                                                                keyContext,
                                                                                out MatchType1) as PartFeature;


                Byte[] refKey2 = set["OccurrenceRefKey"].Value as Byte[];

                object MatchType2;

                occurrence = ParentDocument.ReferenceKeyManager.BindKeyToObject(ref refKey2,
                                                                                keyContext,
                                                                                out MatchType2) as ComponentOccurrence;

                if (asmFeature != null && occurrence != null)
                {
                    return(true);
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 28
0
        void DocumentEvents_OnChangeSelectSet(
            EventTimingEnum BeforeOrAfter,
            NameValueMap Context,
            out HandlingCodeEnum HandlingCode)
        {
            HandlingCode = HandlingCodeEnum.kEventNotHandled;

            if (!_InventorSelectionEnabled)
            {
                return;
            }

            try
            {
                if (BeforeOrAfter == EventTimingEnum.kAfter)
                {
                    if (ActiveDocument.SelectSet.Count != 0)
                    {
                        object obj = ActiveDocument.SelectSet[ActiveDocument.SelectSet.Count];

                        if (obj is ComponentOccurrence)
                        {
                            ComponentOccurrence occurrence = obj as ComponentOccurrence;

                            foreach (TreeNode childNode in _treeView.Nodes[0].Nodes)
                            {
                                foreach (TreeNode subChildNode in childNode.Nodes)
                                {
                                    TreeNodeTag tag = subChildNode.Tag as TreeNodeTag;

                                    if (tag.Occurrences.Contains(occurrence))
                                    {
                                        childNode.Expand();

                                        _treeView.SelectedNode = subChildNode;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
    /// <summary>
    /// Adds the mesh for the given component, and all its subcomponents to the mesh storage structure.
    /// </summary>
    /// <param name="occ">The component to export</param>
    /// <param name="bestResolution">Use the best possible resolution</param>
    /// <param name="separateFaces">Export each face as a separate mesh</param>
    /// <param name="ignorePhysics">Don't add the physical properties of this component to the exporter</param>
    /// <returns>All the sufaces to export</returns>
    private List <ExportPlan> GenerateExportList(ComponentOccurrence occ, bool bestResolution = false, bool separateFaces = false, bool ignorePhysics = false)
    {
        List <ExportPlan> plannedExports = new List <ExportPlan>();

        if (!ignorePhysics)
        {
            // Compute physics
            try
            {
                outputMesh.physics.Add((float)occ.MassProperties.Mass, Utilities.ToBXDVector(occ.MassProperties.CenterOfMass));
                Console.WriteLine(InventorManager.Instance.ActiveDocument.UnitsOfMeasure.MassUnits.ToString());
            }
            catch
            {
            }
        }

        if (!occ.Visible)
        {
            return(plannedExports);
        }

        foreach (SurfaceBody surf in occ.SurfaceBodies)
        {
            Console.Write("Including: " + surf.Parent.Name);
            plannedExports.Add(new ExportPlan(surf, bestResolution, separateFaces));
        }

        double totalVolume = 0;

        foreach (ComponentOccurrence occ2 in occ.SubOccurrences)
        {
            totalVolume += Utilities.BoxVolume(occ2.RangeBox);
        }
        totalVolume /= occ.SubOccurrences.Count * adaptiveDegredation;

        foreach (ComponentOccurrence item in occ.SubOccurrences)
        {
            if (!adaptiveIgnoring || Utilities.BoxVolume(item.RangeBox) >= totalVolume)
            {
                plannedExports.AddRange(GenerateExportList(item, bestResolution, separateFaces, true));
            }
        }
        return(plannedExports);
    }
Ejemplo n.º 30
0
 private void button1_Click(object sender, EventArgs e)
 {
     a = Convert.ToDouble(this.textBox1.Text.Replace(',', separator)) / 10;
     b = Convert.ToDouble(this.textBox2.Text.Replace(',', separator)) / 10;
     this.Hide();
     try
     {
         invApp = (Inventor.Application)m_PartDoc.Parent;
         if (m_PartDoc.SubType == "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}")
         {
             smcd = (SheetMetalComponentDefinition)m_PartDoc.ComponentDefinition;
         }
         tr     = invApp.TransactionManager.StartTransaction((_Document)m_PartDoc, "Шипы");
         objCol = invApp.TransientObjects.CreateObjectCollection();
         if (asmDoc != null)
         {
             ComponentOccurrence co = asmDoc.ComponentDefinition.Occurrences.OfType <ComponentOccurrence>().FirstOrDefault(c => c.Name.ToLower().IndexOf("обтекатель") != -1);
             if (co != null)
             {
                 //PartDocument pDoc;
                 if (((Document)co.Definition.Document).SubType == "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}")
                 {
                     smcd = (SheetMetalComponentDefinition)((PartDocument)co.Definition.Document).ComponentDefinition;
                 }
                 PlanarSketch plsk = smcd.Sketches.OfType <PlanarSketch>().FirstOrDefault(p => p.Name == "Шип");
                 if (plsk == null)
                 {
                     project(smcd, "Шип");
                 }
             }
             return;
         }
         profiles = selectFromSketch();
         //offsetAdaptive(profiles);
         offset(profiles);
         tr.End();
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         tr.End();
         this.Close();
     }
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Allows the user to see if they have already added a collision component in select mode.
        /// </summary>
        /// <param name="PreSelectEntity"></param>
        /// <param name="DoHighlight"></param>
        /// <param name="MorePreSelectEntities"></param>
        /// <param name="SelectionDevice"></param>
        /// <param name="ModelPosition"></param>
        /// <param name="ViewPosition"></param>
        /// <param name="View"></param>
        void selectEvents_OnPreSelect(ref object PreSelectEntity, out bool DoHighlight, ref ObjectCollection MorePreSelectEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
        {
            DoHighlight = true;

            if (PreSelectEntity is ComponentOccurrence)
            {
                ComponentOccurrence componentOccurrence = (ComponentOccurrence)PreSelectEntity;

                if (CollisionObjectsView.Nodes.Find(componentOccurrence.Name, true).Length > 0)
                {
                    CollisionObjectsView.Invoke(new Action(() =>
                    {
                        CollisionObjectsView.SelectedNode = CollisionObjectsView.Nodes.Find(componentOccurrence.Name, true)[0];
                        CollisionObjectsView.SelectedNode.EnsureVisible();
                    }));
                }
            }
        }
 public OccurenceWrapper(ComponentOccurrence oCompOc)
 {
     nativeCompOccurence = oCompOc;
 }
Ejemplo n.º 33
0
 public void GetSelectedObject(GenericObject selection, out ObjectTypeEnum objectType, out NameValueMap additionalData, out ComponentOccurrence containingOccurrence, ref Object selectedObject)
 {
     InternalGetSelectedObject( selection, out  objectType, out  additionalData, out  containingOccurrence, ref  selectedObject);
 }
Ejemplo n.º 34
0
 private void InternalGetSelectedObject(GenericObject selection, out ObjectTypeEnum objectType, out NameValueMap additionalData, out ComponentOccurrence containingOccurrence, ref Object selectedObject)
 {
     PartDocumentInstance.GetSelectedObject( selection, out  objectType, out  additionalData, out  containingOccurrence, ref  selectedObject);
 }
Ejemplo n.º 35
0
        public void CreateAttribute(ComponentOccurrence myPart)
        {
            AttributeSets attribSets;
            attribSets = myPart.AttributeSets;

            AttributeSet attribSet;

            if((attribSet = attribSets.Add("MyAttribSet", false)) == null)
            {
                attribSet = attribSets["MyAttribSet"];
            }

            Inventor.Attribute attrib;
            if(attribSet.Count == 0)
            {
                attrib = attribSet.Add("MyAttrib", ValueTypeEnum.kStringType, "Some Text");
            }
        }
Ejemplo n.º 36
0
        public void DeleteAttributes(ComponentOccurrence myPart)
        {
            AttributeSets attribSets;
            attribSets = myPart.AttributeSets;

            if(attribSets.get_NameIsUsed("MyAttribSet"))
            {
                Inventor.Attribute attrib;
                attrib = attribSets["MyAttribSet"]["MyAttrib"];
                attrib.Delete();
                attribSets["MyAttribSet"].Delete();
            }
        }
Ejemplo n.º 37
0
        public void RetrievAttributes(ComponentOccurrence myPart)
        {
            AttributeSets attribSets;
            attribSets = myPart.AttributeSets;

            Inventor.Attribute attrib;
            attrib = attribSets["MyAttribSet"]["MyAttrib"];

            MessageBox.Show(attrib.Value.ToString());
        }
Ejemplo n.º 38
0
        internal void PlaceWorkGeometryForContsraints(PartComponentDefinition layoutComponentDefinition, ComponentOccurrence layoutOccurrence, int moduleNumber)
        {
            PartDocument partDoc = (PartDocument)layoutComponentDefinition.Document;
            ReferenceKeyManager refKeyManager = partDoc.ReferenceKeyManager;
            
            //TODO: Property ModuleId can be factored out and _binder.ContextData can be used instead.
            ModuleId = moduleNumber;

            for (int i = 0; i < PointObjects.Count; i++)
            {
                //Each ModuleObject needs to have its ContextManager set.
                PointObjects[i].Binder.ContextManager.BindingContextManager = refKeyManager;
                WorkPoint workPoint;
                if (PointObjects[i].Binder.GetObjectFromTrace<WorkPoint>(out workPoint))
                {
                    Inventor.Point newLocation = PersistenceManager.InventorApplication.TransientGeometry.CreatePoint(InternalModulePoints[i].X,
                                                                                                                              InternalModulePoints[i].Y,
                                                                                                                              InternalModulePoints[i].Z);

                    workPoint.SetFixed(InternalModulePoints[i].ToPoint());
                }

                else
                {
                    workPoint = layoutComponentDefinition.WorkPoints.AddFixed(InternalModulePoints[i].ToPoint(), false);
                    PointObjects[i].Binder.SetObjectForTrace<WorkPoint>(workPoint, ModuleUtilities.ReferenceKeysSorter);
                }

                //workPoint.Visible = false;

                object workPointProxyObject;
                layoutOccurrence.CreateGeometryProxy(workPoint, out workPointProxyObject);
                LayoutWorkPointProxies.Add((WorkPointProxy)workPointProxyObject);
                LayoutWorkPoints.Add(workPoint);
            }

            //If we will have more than 2 constraints, it will help assembly stability later
            //if we have a plane to constrain to first.
            if (InternalModulePoints.Count > 2)
            {
                
                WorkPlane workPlane;
                //TODO: Is this a good idea? Why is this a list? Will we ever have more
                //than work plane?  
                PlaneObjects[0].Binder.ContextManager.BindingContextManager = refKeyManager;
                if (PlaneObjects[0].Binder.GetObjectFromTrace<WorkPlane>(out workPlane))
                {
                    if (workPlane.DefinitionType == WorkPlaneDefinitionEnum.kThreePointsWorkPlane)
                    {
                        workPlane.SetByThreePoints(LayoutWorkPoints[0], LayoutWorkPoints[1], LayoutWorkPoints[2]);
                        LayoutWorkPlane = workPlane;
                        object wPlaneProxyObject;
                        layoutOccurrence.CreateGeometryProxy(workPlane, out wPlaneProxyObject);
                        LayoutWorkPlaneProxy = (WorkPlaneProxy)wPlaneProxyObject;
                    }
                }
                else
                {
                    //If the first three points are colinear, adding a workplane will fail.  We will check the area of a triangle 
                    //described by the first three points. If the area is very close to 0, we can assume these points are colinear, and we should
                    //not attempt to construct a work plane from them.
                    Inventor.Point pt1 = LayoutWorkPoints[0].Point;
                    Inventor.Point pt2 = LayoutWorkPoints[1].Point;
                    Inventor.Point pt3 = LayoutWorkPoints[2].Point;
                    if (Math.Abs(pt1.X * (pt2.Y - pt3.Y) + pt2.X * (pt3.Y - pt1.Y) + pt3.X * (pt1.Y - pt2.Y)) > .0000001)
                    {
                        workPlane = layoutComponentDefinition.WorkPlanes.AddByThreePoints(LayoutWorkPoints[0], LayoutWorkPoints[1], LayoutWorkPoints[2], false);
                        PlaneObjects[0].Binder.SetObjectForTrace<WorkPlane>(workPlane, ModuleUtilities.ReferenceKeysSorter);
                        workPlane.Grounded = true;
                        //workPlane.Visible = false;
                        LayoutWorkPlane = workPlane;
                        object wPlaneProxyObject;
                        layoutOccurrence.CreateGeometryProxy(workPlane, out wPlaneProxyObject);
                        LayoutWorkPlaneProxy = (WorkPlaneProxy)wPlaneProxyObject;
                    }
                }
            }
        }