Esempio n. 1
0
 /// <summary>
 /// Enables the "Add Selection" button when an object in Inventor is selected.
 /// </summary>
 /// <param name="JustSelectedEntities"></param>
 /// <param name="SelectionDevice"></param>
 /// <param name="ModelPosition"></param>
 /// <param name="ViewPosition"></param>
 /// <param name="View"></param>
 private void selectEvents_OnSelect(ObjectsEnumerator JustSelectedEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
 {
     if (!addSelectionButton.Enabled)
     {
         addSelectionButton.Invoke(new Action(() =>
         {
             addSelectionButton.Enabled = true;
         }));
     }
 }
Esempio n. 2
0
 public static Autodesk.DesignScript.Geometry.Point ToPoint(this Inventor.Point xyz)
 {
     return(Autodesk.DesignScript.Geometry.Point.ByCoordinates(xyz.X, xyz.Y, xyz.Z));
 }
Esempio n. 3
0
        public override void OnPreSelect(object preSelectEntity, out bool doHighlight, ObjectCollection morePreSelectEntities, SelectionDeviceEnum selectionDevice, Inventor.Point modelPosition, Point2d viewPosition, Inventor.View view)
        {
            doHighlight = false;

            if (preSelectEntity is Face)
            {
                Face preSelectFace = (Face)preSelectEntity;

                if (preSelectFace.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                {
                    PartDocument oPartDoc = (PartDocument)m_inventorApplication.ActiveDocument;

                    iFeatures oiFeatures = oPartDoc.ComponentDefinition.Features.iFeatures;

                    foreach (iFeature oiFeature in oiFeatures)
                    {
                        Faces oFaces;
                        oFaces = oiFeature.Faces;
                        foreach (Face oFace in oFaces)
                        {
                            if (oFace == preSelectFace)
                            {
                                doHighlight = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public override void OnSelect(ObjectsEnumerator justSelectedEntities, SelectionDeviceEnum selectionDevice, Inventor.Point modelPosition, Point2d viewPosition, Inventor.View view)
        {
            int nomb = justSelectedEntities.Count;

            if (nomb > 0)
            {
                object selectedEntity = justSelectedEntities[1];

                if (m_insertOutlineForm.checkBoxChoose.Checked)
                {
                    m_selectFace = (Face)selectedEntity;

                    m_insertOutlineForm.checkBoxChoose.Checked = false;
                }

                this.GetSelectiFeature(m_selectFace, ref m_selectiFeature);

                m_selectEvents.AddToSelectedEntities(m_selectiFeature);

                DisableInteraction();
                //this.HighlightSelectEntity(m_selectiFeature);
                UpdateCommandStatus();
            }
        }
Esempio n. 5
0
 private void selPt(MouseButtonEnum Button, ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
 {
     insPt = ModelPosition;
     flag  = false;
 }
Esempio n. 6
0
 private void m_SelectEvents_OnSelect(Inventor.ObjectsEnumerator JustSelectedEntities, Inventor.SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
 {
     //reserved for future
 }
Esempio n. 7
0
        private void m_MouseEvents_OnMouseDown(Inventor.MouseButtonEnum Button, Inventor.ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
        {
            //if the interaction event is MyScreenshot,
            //then get the view position and model position

            if (m_InteractionEvents.Name == "MyScreenshot")
            {
                m_MouseStartViewPt = ViewPosition;
                m_StartModelPt     = ModelPosition;
                m_flagMouseDown    = true;

                //clean the last graphics
                m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.Delete();
                m_inventorApplication.ActiveView.Update();

                //gi node
                oGiNode   = m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.AddNode(1);
                oCoordSet = m_InteractionEvents.InteractionGraphics.GraphicsDataSets.CreateCoordinateSet(1);

                //color set
                oColorSet = m_InteractionEvents.InteractionGraphics.GraphicsDataSets.CreateColorSet(1);
                oColorSet.Add(1, 255, 0, 0);

                TransientGeometry tg    = m_inventorApplication.TransientGeometry;
                Inventor.Point    tempP = tg.CreatePoint(ViewPosition.X, ViewPosition.Y, 0);

                oCoordSet.Add(1, tempP);
                oCoordSet.Add(2, tempP);
                oCoordSet.Add(3, tempP);
                oCoordSet.Add(4, tempP);
                oCoordSet.Add(5, tempP);

                try
                {
                    if (oGiLineStripG != null)
                    {
                        oGiLineStripG.Delete();
                        oGiLineStripG = null;
                    }
                    oGiLineStripG = oGiNode.AddLineStripGraphics();
                    oGiLineStripG.CoordinateSet = oCoordSet;
                    oGiLineStripG.ColorSet      = oColorSet;
                    oGiLineStripG.BurnThrough   = true;
                }
                catch (Exception ex)
                {
                    //a problem in Inventor 2009( R13 ) with
                    //LineStripGraphics.BurnThrough. Use LineGraphics as workaround

                    if (oGiLineG != null)
                    {
                        oGiLineG.Delete();
                        oGiLineG = null;
                    }

                    oGiLineG = oGiNode.AddLineGraphics();
                    oGiLineG.CoordinateSet = oCoordSet;
                    oGiLineG.ColorSet      = oColorSet;
                    oGiLineG.BurnThrough   = true;
                }
            }
        }
Esempio n. 8
0
 public void Addpoint(out Inventor.Point point)
 {
     point = this.m_Point;
 }
Esempio n. 9
0
        private void ProjectPoint(Inventor.Point ModelPosition, Inventor.Point WorkPointPosition, out Inventor.Point ProjectedPoint)
        {
            //Set a reference to the camera object
            Inventor.Camera oCamera;
            oCamera = m_inventorApplication.ActiveView.Camera;

            Vector oVector;

            oVector = oCamera.Eye.VectorTo(oCamera.Target);

            Line oLine;

            oLine = m_inventorApplication.TransientGeometry.CreateLine(ModelPosition, oVector);

            //Create the z-axis vector
            Vector oZAxis;

            oZAxis = m_inventorApplication.TransientGeometry.CreateVector(0, 0, 1);

            //Create a plane parallel to the X-Y plane
            Plane oWPPlane;

            oWPPlane = m_inventorApplication.TransientGeometry.CreatePlane(WorkPointPosition, oZAxis);

            ProjectedPoint = oWPPlane.IntersectWithLine(oLine);
        }
Esempio n. 10
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();
                    }));
                }
            }
        }
Esempio n. 11
0
        //Generate SDF file.
        private void GenerateSDF()
        {
            UnitsOfMeasure              oUOM        = _invApp.ActiveDocument.UnitsOfMeasure;
            AssemblyDocument            oAsmDoc     = (AssemblyDocument)_invApp.ActiveDocument;
            AssemblyComponentDefinition oAsmCompDef = oAsmDoc.ComponentDefinition;
            List <ComponentOccurrence>  compOccurs  = new List <ComponentOccurrence>();
            List <AssemblyConstraint>   constraints = new List <AssemblyConstraint>();

            //Recursively make a list of all component parts.
            List <AssemblyComponentDefinition> loopList = new List <AssemblyComponentDefinition>();

            //TODO: Store OccuranceName vs Pose for assemblies.
            loopList.Add((AssemblyComponentDefinition)oAsmCompDef);
            //Recursively make a list of all component parts.
            while (loopList.Count > 0)
            {
                AssemblyComponentDefinition loopAsmCompDef = loopList[0];
                loopList.RemoveAt(0);
                foreach (ComponentOccurrence occ in loopAsmCompDef.Occurrences)
                {
                    if (occ.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject || occ.Definition is WeldmentComponentDefinition)
                    {
                        //Store parts and weldments for link creation
                        compOccurs.Add(occ);
                        //occ.

                        WriteLine("Processing part '" + occ.Name + "' with " + occ.Constraints.Count + " constraints.");
                    }
                    else if (occ.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                    {
                        //Get parts from assemblies.
                        loopList.Add((AssemblyComponentDefinition)occ.Definition);

                        WriteLine("Processing assembly '" + occ.Name + "' with " + occ.Constraints.Count + " constraints.");
                    }
                }

                //Get Assembly Constraints
                foreach (AssemblyConstraint cons in loopAsmCompDef.Constraints)
                {
                    constraints.Add(cons);
                }
            }

            WriteLine(compOccurs.Count.ToString() + " parts to convert.");
            WriteLine(constraints.Count.ToString() + " constraints to convert.");

            //Get all the available links
            foreach (ComponentOccurrence oCompOccur in compOccurs)
            {
                //Define a link
                Link link = new Link(RemoveColon(oCompOccur.Name));

                //Get global position and COM
                double Mass = oCompOccur.MassProperties.Mass;

                //Calculate rotation.
                Inventor.Matrix R1 = oCompOccur.Transformation;

                // Set position and rotation
                //TODO: Check globalised scale
                //TODO: Set pose relative to parent occurance.
                link.Pose = new Pose(R1, precision, scale);

                // Get Moments of Inertia.
                double[] iXYZ = new double[6];
                //Pos of C.O.M., Rot of Link.
                // Ixx, Iyy, Izz, Ixy, Iyz, Ixz
                // Ixx, Ixy, Ixz, Iyy, Iyz, Izz
                oCompOccur.MassProperties.XYZMomentsOfInertia(out iXYZ[0], out iXYZ[3], out iXYZ[5], out iXYZ[1], out iXYZ[4], out iXYZ[2]);
                Inventor.Point COMp = oCompOccur.MassProperties.CenterOfMass;
                double[]       COM  = new double[3] {
                    COMp.X, COMp.Y, COMp.Z
                };

                // Set Moments of Inertia
                //Takes precision from link.Pose.
                link.Inertial = new Inertial(Mass, iXYZ, COM, link.Pose, scale);

                // Set the URI for the link's model.
                String URI = "model://<MODELNAME>/meshes/" + link.Name + ".stl";
                link.Visual    = new Visual(new Mesh(URI, scale));
                link.Collision = new Collision(new Mesh(URI, scale));

                // Print out link information.
                WriteLine("New Link:          --------------------------------------");
                WriteLine("                  Name: " + link.Name);
                WriteLine("                  Pose: " + link.Pose.ToString());
                //link.Pose = new Pose(link.Pose);
                WriteLine("                  Pose: " + link.Pose.ToString());
                WriteLine("           InertiaPose: " + link.Inertial.Pose.ToString());
                Matrix <double> M2 = DenseMatrix.OfArray(link.Inertial.InertiaMatrix);
                WriteLine(M2.ToString());
                WriteLine("                  Mass: " + Mass);
                WriteLine("       Rotation Matrix: " + System.Environment.NewLine + link.Pose.PrintMatrix());

                // Add link to robot
                robo.Links.Add(link);
            }

            WriteLine(constraints.Count.ToString() + " constraints to convert.");

            //Get all the available joints
            foreach (AssemblyConstraint constraint in constraints)
            {
                //Some checks
                if (constraint.Suppressed)
                {
                    //Skip suppressed constraints.
                    WriteLine("Skipped a suppressed constraint.");
                    continue;
                }



                //Set some starting variables.
                String         name = constraint.Name;
                Inventor.Point center;
                JointType      type = JointType.Revolute;

                //Calculate which should be child.
                ComponentOccurrence childP  = constraint.OccurrenceOne;
                ComponentOccurrence parentP = constraint.OccurrenceTwo;
                if (childP == null || parentP == null)
                {
                    //Skip incomplete constraints
                    WriteLine("Skipped a constraint without an Occurance.");
                    continue;
                }

                //Get degrees of freedom information.
                int transDOFCount, rotDOFCount;
                Inventor.ObjectsEnumerator transDOF, rotDOF;
                Inventor.Point             DOFCenter;
                childP.GetDegreesOfFreedom(out transDOFCount, out transDOF, out rotDOFCount, out rotDOF, out DOFCenter);
                if (rotDOFCount + transDOFCount == 0)
                {
                    parentP.GetDegreesOfFreedom(out transDOFCount, out transDOF, out rotDOFCount, out rotDOF, out DOFCenter);
                    if (rotDOFCount + transDOFCount == 0)
                    {
                        WriteLine("Skipped a constraint with 0 DOF.");
                        continue;
                    }
                    //Parent has DOF but child doesn't. Switch Parent and Child.
                    ComponentOccurrence temp = childP;
                    childP  = parentP;
                    parentP = temp;
                }

                //Get Model Links
                Link child  = GetLinkByName(RemoveColon(childP.Name));
                Link parent = GetLinkByName(RemoveColon(parentP.Name));
                if (child == null || parent == null)
                {
                    //Skip incomplete constraints
                    WriteLine("Skipped a constraint without a Link.");
                    continue;
                }

                //Get constraint information
                Pose           Pose;
                Axis           Axis;
                Inventor.Point Geomcenter;
                if (constraint is InsertConstraint && constraint.GeometryOne is Circle)
                {
                    //Handle Insert Constraints (Revolute)
                    Circle circ = (Circle)constraint.GeometryOne;
                    Geomcenter = circ.Center;
                    Axis       = new Axis(circ.Normal.X, circ.Normal.Y, circ.Normal.Z);
                    type       = JointType.Revolute;
                }
                else if (constraint is MateConstraint && constraint.GeometryOne is Line)
                {
                    //Handle Mate Constraints (Prismatic)
                    Inventor.Line line = (Line)constraint.GeometryOne;
                    Geomcenter = line.RootPoint;
                    //TODO: Find out if axis is global, or local to assembly.
                    Axis = new Axis(line.Direction.X, line.Direction.Y, line.Direction.Z);
                    type = JointType.Prismatic;
                }
                else
                {
                    //Skip other constraints
                    WriteLine("Skipped an uknown constraint");
                    continue;
                }
                Pose = new Pose(Geomcenter.X, Geomcenter.Y, Geomcenter.Z, precision, scale);

                WriteLine("New joint:          --------------------------------------");
                WriteLine("                Name: " + name);
                WriteLine("              Parent: " + parent.Name);
                WriteLine("               Child: " + child.Name);
                WriteLine("                Pose: " + Pose.ToString());
                Pose.GetPosRelativeTo(child.Pose);
                WriteLine("           Child Loc: " + child.Pose.ToString());
                WriteLine("       Relative Pose: " + Pose.ToString());
                WriteLine("                Axis: " + Axis.ToString());
                WriteLine("              rotDOF: " + rotDOFCount + "    transDOF: " + transDOFCount);

                //Add the joint to the robot
                Joint joint = new Joint(name, type);
                joint.Axis   = Axis;
                joint.Parent = parent;
                joint.Child  = child;
                joint.Pose   = Pose;
                robo.Joints.Add(joint);
            }

            //Saving turned on?
            if (this.checkBox2.Checked)
            {
                // Save the SDF
                FolderBrowserDialog folderDialog1 = new FolderBrowserDialog();
                if (folderDialog1.ShowDialog() == DialogResult.OK)
                {
                    robo.WriteSDFToFile(folderDialog1.SelectedPath, precision);
                }

                //Save STLs?
                foreach (ComponentOccurrence oCompOccur in compOccurs)
                {
                    if (oCompOccur.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject && this.checkBox1.Checked)
                    {
                        PartDocument partDoc = (PartDocument)oCompOccur.Definition.Document;
                        partDoc.SaveAs(folderDialog1.SelectedPath + "\\meshes\\" + RemoveColon(oCompOccur.Name) + ".stl", true);
                        WriteLine("Finished saving: " + folderDialog1.SelectedPath + "\\meshes\\" + RemoveColon(oCompOccur.Name) + ".stl");
                    }
                }
            }

            #region oldcode
            //foreach (ComponentOccurrence oCompOccur in oAsmCompDef.Occurrences)
            //{
            //    // Generate links from available subassemblies in main assembly.
            //    //Debugger.Break();

            //    //New Link
            //    robo.Links.Add(new Link(oCompOccur.Name));
            //    int c = robo.Links.Count - 1;

            //    WriteLine("Added Link: "+ robo.Links[c].Name +", link count: " + robo.Links.Count.ToString());

            //    //Find and set parent link
            //    for (int i = 0; i < robo.Links.Count; i++)
            //    {
            //        if (String.Equals(robo.Links[i].Name, ReturnParentName(oCompOccur)))
            //        {
            //            robo.Links[c].Parent = robo.Links[i];
            //            WriteLine("Link's parent: " + robo.Links[i].Name);
            //        }
            //    }



            //    //If link has a parent
            //    if (robo.Links[c].Parent != null)
            //    {
            //        //Define a joint
            //        robo.Joints.Add(new Joint(FormatJointName(robo.Links[c].Name), JointType.Revolute, robo.Links[c].Parent, robo.Links[c]));
            //        int j = robo.Joints.Count - 1;

            //        //Parse joint axis
            //        switch (robo.Joints[j].Name[robo.Joints[j].Name.Length - 1])
            //        {
            //            case 'R':
            //                robo.Joints[j].Axis = new double[] { 1, 0, 0 };
            //                break;
            //            case 'P':
            //                robo.Joints[j].Axis = new double[] { 0, 1, 0 };
            //                break;
            //            case 'Y':
            //                robo.Joints[j].Axis = new double[] { 0, 0, 1 };
            //                break;
            //            default:
            //                break;
            //        }
            //    }

            //    // Get mass properties for each link.
            //    double[] iXYZ = new double[6];
            //    oCompOccur.MassProperties.XYZMomentsOfInertia(out iXYZ[0], out iXYZ[3], out iXYZ[5], out iXYZ[1], out iXYZ[4], out iXYZ[2]); // Ixx, Iyy, Izz, Ixy, Iyz, Ixz -> Ixx, Ixy, Ixz, Iyy, Iyz, Izz
            //    robo.Links[c].Inertial = new Inertial(oCompOccur.MassProperties.Mass, iXYZ);
            //    robo.Links[c].Inertial.XYZ = FindCenterOfMassOffset(oCompOccur);

            //    // Set shape properties for each link.
            //    robo.Links[c].Visual = new Visual(new Mesh("package://" + robo.Name + "/" + robo.Links[c].Name + ".stl"));
            //}
            #endregion
        }
Esempio n. 12
0
 private void selectEvents_OnSelect(ObjectsEnumerator JustSelectedEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
 {
 }
Esempio n. 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.Hide();
                double h = 1, w = 1;
                if (m_Asm != null)
                {
                    CommandManager cmdMgr = invApp.CommandManager;
                    string         txt    = "";
                    //input = cmdMgr.UserInputEvents;
                    intEvts = cmdMgr.CreateInteractionEvents();
                    intEvts.InteractionDisabled = false;
                    sel = intEvts.SelectEvents;
                    sel.AddSelectionFilter(SelectionFilterEnum.kPartFaceFilter);
                    sel.OnSelect       += new SelectEventsSink_OnSelectEventHandler(select);
                    mouse               = intEvts.MouseEvents;
                    mouse.OnMouseClick += new MouseEventsSink_OnMouseClickEventHandler(selPt);
                    intEvts.Start();
                    intEvts.StatusBarText = "Выберите поверхность:";
                    //input.OnSelect += new UserInputEventsSink_OnSelectEventHandler(select);
                    //face = (Face)cmdMgr.Pick(SelectionFilterEnum.kPartFaceFilter, "Выберите поверхность:");
                    //input.OnSelect -= new UserInputEventsSink_OnSelectEventHandler(select);
                    flag = true;
                    while (flag)
                    {
                        invApp.UserInterfaceManager.DoEvents();
                    }
                    intEvts.Stop();
                    sel.OnSelect -= new SelectEventsSink_OnSelectEventHandler(select);
                    intEvts.MouseEvents.OnMouseClick -= new MouseEventsSink_OnMouseClickEventHandler(selPt);
                    List <string> tmp  = new List <string>();
                    string        name = comboBox1.Text;
                    m_Doc = (PartDocument)invApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, CreateVisible: false);
                    m_Doc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure;
                    m_Doc.UnitsOfMeasure.LengthUnits       = UnitsTypeEnum.kMillimeterLengthUnits;
                    string filename = "";
                    for (int i = 0; i < attrXML.Count; i++)
                    {
                        if (attrXML[i].StartsWith("Name=" + name))
                        {
                            tmp.Add(attrXML[i]);
                            tmp.Add(valXML[i]);
                            i++;
                            while (i < attrXML.Count && attrXML[i].StartsWith("RowHeight="))
                            {
                                tmp.Add(attrXML[i]);
                                tmp.Add(valXML[i]);
                                i++;
                            }
                            break;
                        }
                    }
                    string nameStricker = "";
                    string strTmp       = tbl.substring(tmp[0], "PartNumber=");
                    nameStricker = strTmp;
                    if (strTmp != "")
                    {
                        m_Doc.PropertySets[3][2].Value = strTmp; filename += strTmp;
                    }
                    strTmp = tbl.substring(tmp[0], "Description=");
                    if (strTmp != "")
                    {
                        m_Doc.PropertySets[3][14].Value = strTmp;
                        filename += (filename == "") ? strTmp : "-" + strTmp;
                    }

                    Func <string, double> conv = s =>
                    {
                        char rep = (separator == ',') ? '.' : ',';
                        return((s.IndexOf(separator) != -1) ? Convert.ToDouble(s) : Convert.ToDouble(s.Replace(rep, separator)));
                    };

                    strTmp = tbl.substring(tmp[0], "Height=");
                    if (strTmp != "")
                    {
                        h = conv(strTmp);
                    }
                    strTmp = tbl.substring(tmp[0], "Width=");
                    if (strTmp != "")
                    {
                        w = conv(strTmp);
                    }
                    strTmp = tbl.substring(tmp[0], "txt=");
                    if (strTmp != "")
                    {
                        txt = strTmp;
                    }
                    strTmp = tbl.substring(tmp[0], "Sort=");
                    if (strTmp != "")
                    {
                        m_Doc.PropertySets[1][4].Value = strTmp;
                    }
                    strTmp = tbl.substring(tmp[0], "Note=");
                    if (strTmp != "")
                    {
                        m_Doc.PropertySets[1][5].Value = strTmp;
                    }
                    strTmp = tbl.substring(tmp[0], "Triangle=");
                    if (strTmp == "False")
                    {
                        triangle = false;
                    }
                    else
                    {
                        triangle = true;
                    }
                    strTmp = tbl.substring(tmp[0], "Offset1=");
                    if (strTmp != "")
                    {
                        offset1 = conv(strTmp) / 10;
                    }
                    strTmp = tbl.substring(tmp[0], "Offset2=");
                    if (strTmp != "")
                    {
                        offset2 = conv(strTmp) / 10;
                    }
                    strTmp = tbl.substring(tmp[0], "Mirror=");
                    if (strTmp != "")
                    {
                        mirror = true;
                    }

                    if (face.SurfaceType == SurfaceTypeEnum.kPlaneSurface)
                    {
                        filename += "-" + w.ToString() + "x" + h.ToString();
                        if (!System.IO.File.Exists(path(m_Asm.FullFileName) + filename + ".ipt"))
                        {
                            Plane plane = (Plane)face.Geometry;
                            vecZ = plane.Normal;
                            if (!triangle)
                            {
                                planarSticker(ref m_Doc, h, w, txt);
                            }
                            else
                            {
                                triangleSticker(ref m_Doc, h, w, txt);
                            }
                        }
                    }
                    else if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                    {
                        R         = Math.Round(((Cylinder)face.Geometry).Radius, 2);
                        filename += "-" + w.ToString() + "x" + h.ToString() + "x" + (R * 10).ToString();
                        if (!System.IO.File.Exists(path(m_Asm.FullFileName) + filename + ".ipt"))
                        {
                            if (this.radioButton1.Checked)
                            {
                                circleSticker(ref m_Doc, w, h, R, txt); filename += "(верт)";
                            }
                            else
                            {
                                circleSticker(ref m_Doc, h, w, R, txt);
                            }
                        }
                    }
                    filename = path(m_Asm.FullFileName) + filename + ".ipt";
                    if (!System.IO.File.Exists(filename))
                    {
                        m_Doc.SaveAs(filename, false);
                        Document tmp_Doc = invApp.Documents.Open(filename, false);
                        tmp_Doc.PropertySets[3][2].Value = nameStricker;
                        tmp_Doc.Save();
                        tmp_Doc.Close();
                        m_Doc.Close();
                    }

                    Inventor.Point pt = m_TG.CreatePoint();
                    //pos = m_TG.CreateMatrix();


                    //rot.SetCoordinateSystem(insPt, m_TG.CreateVector(YCoord: 1), m_TG.CreateVector(1) , m_TG.CreateVector(ZCoord: 1));

                    //pos.TransformBy(rot);
//                         if (face.SurfaceType == SurfaceTypeEnum.kPlaneSurface && !System.IO.File.Exists(filename))
//                         {

                    //}

                    AssemblyComponentDefinition compDef = m_Asm.ComponentDefinition;
                    //pos.Cell[4, 1] = insPt.X; pos.Cell[4, 2] = insPt.Y; pos.Cell[4, 3] = insPt.Z;
                    rot = m_TG.CreateMatrix();
                    ComponentOccurrence occ = compDef.Occurrences.Add(filename, rot);
                    Vector vec1             = InvDoc.u.getAxis(face);
                    Vector vec2             = InvDoc.u.getAxis(occ);
                    if (!InvDoc.u.eq(vec1, vec2))
                    {
                        rot.SetToRotateTo(vec1, vec2);
                    }
                    //m_Asm.ComponentDefinition.WorkPoints.AddFixed(insPt);
                    vec = pt.VectorTo(insPt);
                    rot.SetTranslation(vec);
                    //rot.Cell[1, 4] = insPt.X; rot.Cell[2, 4] = insPt.Y; rot.Cell[3, 4] = insPt.Z;
                    //occ.Transformation = rot;
                    occ.SetTransformWithoutConstraints(rot);
                    //rot.SetToRotateTo(m_TG.CreateVector(ZCoord: 1), vecZ.AsVector(), m_TG.CreateVector(XCoord: 1));
                    //rot.SetTranslation(vec);
                    //return;
                    //Face face2 = occ.SurfaceBodies[1].Faces[5];
                    object fac = null;
                    occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[3], out fac);
                    WorkPlaneProxy          face2 = (WorkPlaneProxy)fac;
                    PartComponentDefinition def   = (PartComponentDefinition)occ.Definition;
                    //Inventor.Point pt2 = def.WorkPoints[1].Point;
                    //pos.Invert();
                    //pt2.TransformBy(pos);
                    if (face.SurfaceType == SurfaceTypeEnum.kPlaneSurface)
                    {
                        compDef.Constraints.AddFlushConstraint(face, face2, 0);
                    }
                    else if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                    {
                        //foreach (Face f in occ.SurfaceBodies[1].Faces)
                        //{
                        //    if (f.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                        //    {
                        //        if (Math.Round(((Cylinder)f.Geometry).Radius, 2) == R)
                        //        {
                        //            face2 = f; break;
                        //        }
                        //    }
                        //}
                        occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkAxes[2], out fac);
                        compDef.Constraints.AddMateConstraint((WorkAxisProxy)fac, face, 0, InferredTypeEnum.kInferredLine, InferredTypeEnum.kInferredLine);
                    }
                    //Matrix trans = m_TG.CreateMatrix();
                    //trans.SetTranslation(vec,true);
                    //occ.Transformation.Cell[1, 4] = insPt.X; occ.Transformation.Cell[2, 4] = insPt.Y; occ.Transformation.Cell[3, 4] = insPt.Z;

                    object face1 = null;

                    if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                    {
                        if (offset1 > 0.05 && offset1 < 0.4)
                        {
                            //PartComponentDefinition pDef = ((PartDocument)((FaceProxy)face).ContainingOccurrence.Definition.Document).ComponentDefinition;
                            ((FaceProxy)face).ContainingOccurrence.CreateGeometryProxy(InvDoc.u.getPlane((FaceProxy)face), out fac);
                            //createProxy((FaceProxy)face, (int)(offset1 * 10), ref fac);
                            //occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[(int)(offset1 * 10)], out fac);
                            face1   = fac;
                            offset1 = 0;
                        }
                        else /*if (offset1 != 0)*/
                        {
                            offset1 += w / 20;
                            ent      = (Edge)cmdMgr.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Выберите торцевое ребро:");
                            if (ent.Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface)
                            {
                                face1 = ent.Faces[1];
                            }
                            else
                            {
                                face1 = ent.Faces[2];
                            }
                        }
//                         if (offset2 != 0)
//                         {
//                             offset2 += h / 20;
//                         }
                        //face1 = cmdMgr.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Выберите тор"
                    }
                    else
                    {
                        if (offset1 > 0.05 && offset1 < 0.4)
                        {
                            createProxy((FaceProxy)face, (int)(offset1 * 10), ref fac);
                            //occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[(int)(offset1 * 10)], out fac);
                            edge1   = fac;
                            offset1 = 0;
                        }
                        else /*if (offset1 != 0)*/
                        {
                            offset1 += h / 20;
                            edge1    = cmdMgr.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Выберите ребро или плоскость:");
                        }
                    }
                    //face2 = occ.SurfaceBodies[1].Faces[2];
                    occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[2], out fac);
                    face2 = (WorkPlaneProxy)fac;
                    MateConstraint mc = null; FlushConstraint fc = null;

//                     if (offset2 < 0.4)
//                     {
//                         face1 = createProxy(occ, (int)(offset2 * 10)); //compDef.WorkPlanes[(int)(offset2*10)];
//                     }
                    //else if (offset2 != 0) offset2 += h / 20;
                    if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                    {
                        fc = compDef.Constraints.AddFlushConstraint(face2, face1, offset1);
                    }
                    else
                    {
                        mc = compDef.Constraints.AddMateConstraint(face2, edge1, offset1);
                    }
//                     Inventor.Point ptmc = occ.RangeBox.MinPoint;
//                     SelectionFilterEnum [] f = {SelectionFilterEnum.kPartFaceFilter};
//                     ObjectsEnumerator en = compDef.FindUsingPoint(ptmc, ref f, 0.1);
                    if (/*en.Count < 3*/ InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face))
                    {
                        if (mc != null)
                        {
                            mc.Offset.Value = -(double)mc.Offset.Value;
                        }
                        //else fc.Offset.Value = - (double)fc.Offset.Value;
                    }
                    if (offset2 > 0.05 && offset2 < 0.4)
                    {
                        createProxy((FaceProxy)face, (int)(offset2 * 10), ref fac);
                        //occ.CreateGeometryProxy(((PartComponentDefinition)face.ReferenceComponent.ReferencedDocumentDescriptor.ReferencedDocument.Definition).WorkPlanes[(int)(offset2 * 10)], out fac);
                        edge2   = fac;
                        offset2 = 0;
                    }
                    else /*if (offset2 != 0)*/
                    {
                        if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                        {
                            offset2 += h / 20;
                        }
                        else
                        {
                            offset2 += w / 20;
                        }
                        edge2 = cmdMgr.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Выберите ребро или плоскость:");
                    }

                    //face2 = occ.SurfaceBodies[1].Faces[1];
                    occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[1], out fac);
                    face2 = (WorkPlaneProxy)fac;
                    mc    = compDef.Constraints.AddMateConstraint(face2, edge2, offset2);
                    if (mc.HealthStatus == HealthStatusEnum.kInconsistentHealth)
                    {
                        occ.Constraints[2].ConvertToFlushConstraint(occ.Constraints[2].EntityOne, occ.Constraints[2].EntityTwo, offset1);
                    }
                    //en = compDef.FindUsingPoint(ptmc, ref f, 0.1);
                    m_Asm.Update();
                    if (/*en.Count < 3*/ InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face))
                    {
                        mc.Delete();
                        mc = compDef.Constraints.AddMateConstraint(face2, edge2, offset2);
                        m_Asm.Update();
                        if (InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face))
                        {
                            //mc.Delete();
                            //mc = compDef.Constraints.AddMateConstraint(face2, edge1, -offset2);
                            double dist = Macros.StandardAddInServer.m_inventorApplication.MeasureTools.GetMinimumDistance(occ.RangeBox.MinPoint, edge2);
                            if (dist > offset2 * 2)
                            {
                                rot = m_TG.CreateMatrix();
                                Vector tr = occ.Transformation.Translation;
                                rot.SetToRotation(Math.PI, InvDoc.u.getAxis(occ), m_TG.CreatePoint(tr.X, tr.Y, tr.Z));
                                mc.Delete();
                                occ.Transformation = rot;
                                mc = compDef.Constraints.AddMateConstraint(face2, edge2, offset2);
                                if (InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face))
                                {
                                    mc.Offset.Value = -(double)mc.Offset.Value;
                                }
                            }
                            else if (InvDoc.u.intersPoint(compDef, occ, (FaceProxy)face))
                            {
                                mc.Offset.Value = -(double)mc.Offset.Value;
                            }
                            m_Asm.Update();
                        }
                        //mc.Offset.Value = -(double)mc.Offset.Value;
                    }
                    //occ.Transformation = trans;
                }

                this.Close();
            }
            catch (Exception)
            {
                //MessageBox.Show(ex.ToString());
                this.Close();
            }
        }
Esempio n. 14
0
 private void m_SelectEvents_OnSelect(Inventor.ObjectsEnumerator JustSelectedEntities, Inventor.SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
 {
     if (JustSelectedEntities.Count != 0)
     {
         object selectObj1 = JustSelectedEntities[1];
         //object selectObj2 = JustSelectedEntities[2];
         System.Windows.Forms.MessageBox.Show((string)("Selected Entity Type: " + Information.TypeName(selectObj1)) + " , Interactive selection successful!", "Interactive Selection");
     }
 }
Esempio n. 15
0
        // version 2010-05-23: to solve the issue in Perspective View
        private void m_MouseEvents_OnMouseMove(Inventor.MouseButtonEnum Button, Inventor.ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
        {
            //if the interaction event is MyScreenshot, draw selecting rectangle.
            if (m_InteractionEvents.Name == "MyScreenshot" && m_flagMouseDown)
            {
                TransientGeometry tg = m_inventorApplication.TransientGeometry;

                Inventor.Point P1 = tg.CreatePoint(m_MouseStartViewPt.X, -m_MouseStartViewPt.Y, 0);
                Inventor.Point P3 = tg.CreatePoint(ViewPosition.X, -ViewPosition.Y, 0);
                Inventor.Point P4 = tg.CreatePoint(P1.X, P3.Y, 0);
                Inventor.Point P2 = tg.CreatePoint(P3.X, P1.Y, 0);

                //update coordinates

                oCoordSet[1] = P1;
                oCoordSet[2] = P2;
                oCoordSet[3] = P3;
                oCoordSet[4] = P4;
                oCoordSet[5] = P1;

                //add line strip
                if (oGiLineStripG != null)
                {
                    //SetTransformBehavior, default value for PixelScale is 1
                    oGiLineStripG.SetTransformBehavior(P1, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling, 1);
                    oGiLineStripG.SetViewSpaceAnchor(P1, m_MouseStartViewPt, ViewLayoutEnum.kTopLeftViewCorner);
                }
                else if (oGiLineG != null)
                {
                    //SetTransformBehavior, default value for PixelScale is 1
                    oGiLineG.SetTransformBehavior(P1, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling, 1);
                    oGiLineG.SetViewSpaceAnchor(P1, m_MouseStartViewPt, ViewLayoutEnum.kTopLeftViewCorner);
                }


                m_inventorApplication.ActiveView.Update();
            }
        }
Esempio n. 16
0
 public void AddiFeatureFormCmd(string ofilepath, string ofilename, string ocodename, string ocodenumber, string oindexname, string checkfootprint, out Inventor.Point point)
 {
     this.filename       = ofilename;
     this.filepath       = ofilepath;
     this.codename       = ocodename;
     this.codenumber     = ocodenumber;
     this.indexname      = oindexname;
     this.checkfootprint = checkfootprint;
     point = this.m_Point;
 }
Esempio n. 17
0
        private void m_MouseEvents_OnMouseUp(Inventor.MouseButtonEnum Button, Inventor.ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
        {
            //if the interaction event is MyScreenshot, create the image
            if (m_InteractionEvents.Name == "MyScreenshot")
            {
                m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.Delete();
                m_inventorApplication.ActiveView.Update();

                if (oGiLineStripG != null)
                {
                    oGiLineStripG.Delete();
                    oGiLineStripG = null;
                }

                if (oGiLineG != null)
                {
                    oGiLineG.Delete();
                    oGiLineG = null;
                }

                //stop interaction event
                m_InteractionEvents.SetCursor(CursorTypeEnum.kCursorBuiltInArrow);
                m_flagMouseDown = false;
                if (m_MouseEvents != null)
                {
                    m_MouseEvents.OnMouseDown -= m_MouseEvents_OnMouseDown;
                    m_MouseEvents.OnMouseMove -= m_MouseEvents_OnMouseMove;
                    m_MouseEvents.OnMouseUp   -= m_MouseEvents_OnMouseUp;
                    m_MouseEvents              = null;
                }
                m_InteractionEvents.Stop();
                m_InteractionEvents = null;

                //prepare size of the image region, in pixel

                oSize = new Size(Convert.ToInt32(Math.Abs(ViewPosition.X - m_MouseStartViewPt.X)), Convert.ToInt32(Math.Abs(ViewPosition.Y - m_MouseStartViewPt.Y)));

                if (ViewPosition.X > m_MouseStartViewPt.X & ViewPosition.Y > m_MouseStartViewPt.Y)
                {
                    oCornerPt = m_MouseStartViewPt;
                }
                else if (ViewPosition.X > m_MouseStartViewPt.X & ViewPosition.Y < m_MouseStartViewPt.Y)
                {
                    oCornerPt.X = m_MouseStartViewPt.X;
                    oCornerPt.Y = ViewPosition.Y;
                }
                else if (ViewPosition.X <m_MouseStartViewPt.X& ViewPosition.Y> m_MouseStartViewPt.Y)
                {
                    oCornerPt.X = ViewPosition.X;
                    oCornerPt.Y = m_MouseStartViewPt.Y;
                }
                else
                {
                    oCornerPt = ViewPosition;
                }

                //take the view position in screen, calculate
                //the real pixel data of the corners

                oCornerPt.X = (int)View.Left + oCornerPt.X;
                oCornerPt.Y = (int)View.Top + oCornerPt.Y;
            }
        }
Esempio n. 18
0
 private void selectEvts(ObjectsEnumerator JustSelectedEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
 {
     selEvts.AddToSelectedEntities(JustSelectedEntities[1]);
 }
Esempio n. 19
0
 private void select(ObjectsEnumerator JustSelectedEntities, SelectionDeviceEnum SelectionDevice, Inventor.Point ModelPosition, Point2d ViewPosition, Inventor.View View)
 {
     insPt = ModelPosition;
     face  = (Face)JustSelectedEntities[1];
     flag  = false;
 }