예제 #1
0
 /// <summary>
 /// Enables select events when interaction events are activated.
 /// </summary>
 void interactionEvents_OnActivate()
 {
     selectEvents = interactionEvents.SelectEvents;
     selectEvents.AddSelectionFilter(SelectionFilterEnum.kAssemblyOccurrenceFilter);
     selectEvents.OnSelect    += selectEvents_OnSelect;
     selectEvents.OnPreSelect += selectEvents_OnPreSelect;
 }
예제 #2
0
 /////////////////////////////////////////////////////////////
 // Use: Add selection filter.
 //
 /////////////////////////////////////////////////////////////
 public void AddSelectionFilter(SelectionFilterEnum filter)
 {
     if (_SelectEvents != null)
     {
         _SelectEvents.AddSelectionFilter(filter);
     }
 }
예제 #3
0
        //------------------------------------------------------------------------------


        public void Interactive_Selection(Inventor.Application application)
        {
            m_interactionEvents = application.CommandManager.CreateInteractionEvents();

            //设置提示
            m_interactionEvents.StatusBarText = "Select an cylinder face.";

            //连接到相关选择事件
            m_selectEvents = m_interactionEvents.SelectEvents;

            //清除过滤器并重新定义圆柱面可选择
            m_selectEvents.ClearSelectionFilter();
            m_selectEvents.AddSelectionFilter(SelectionFilterEnum.kPartFaceCylindricalFilter);

            //单个选择使能
            m_selectEvents.Enabled             = true;
            m_selectEvents.SingleSelectEnabled = true;

            m_selectEvents.MouseMoveEnabled = false;

            //设置委托
            m_Select_OnSelect_Delegate         = new Inventor.SelectEventsSink_OnSelectEventHandler(this.m_SelectEvents_OnSelect);
            m_selectEvents.OnSelect           += m_Select_OnSelect_Delegate;
            m_interaction_OnTerminate_Delegate = new Inventor.InteractionEventsSink_OnTerminateEventHandler(this.m_InteractionEvent_Onterminate);
            m_interactionEvents.OnTerminate   += m_interaction_OnTerminate_Delegate;

            //启动选择进程
            m_interactionEvents.Start();
        }
예제 #4
0
        public void selOp(ref List <Edge> edgeCmp)
        {
            CommandManager cmdMgr = Macros.StandardAddInServer.m_inventorApplication.CommandManager;

            //input = cmdMgr.UserInputEvents;
            try
            {
                intEvts = cmdMgr.CreateInteractionEvents();
                intEvts.InteractionDisabled = false;
                sel = intEvts.SelectEvents;
                sel.WindowSelectEnabled = true;
                sel.AddSelectionFilter(SelectionFilterEnum.kPartEdgeCircularFilter);
                sel.OnSelect   += new SelectEventsSink_OnSelectEventHandler(select);
                key             = intEvts.KeyboardEvents;
                key.OnKeyPress += new KeyboardEventsSink_OnKeyPressEventHandler(keyOp);
                intEvts.Start();
                intEvts.StatusBarText = "Выберите отверстия:";
                //input.OnSelect += new UserInputEventsSink_OnSelectEventHandler(select);
                //face = (Face)cmdMgr.Pick(SelectionFilterEnum.kPartFaceFilter, "Выберите поверхность:");

                flag = true;
                while (flag)
                {
                    Macros.StandardAddInServer.m_inventorApplication.UserInterfaceManager.DoEvents();
                }

                for (int i = 0; i < sel.SelectedEntities.Count; i++)
                {
                    try
                    {
                        Edge          ed = (Edge)sel.SelectedEntities[i + 1];
                        Inventor.Face f  = (ed.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) ? ed.Faces[1] : ed.Faces[2];
                        edgeCmp.Add(ed);
                        //ed = (f.Edges[1].Equals(ed)) ? f.Edges[2] : f.Edges[1];
                        //edgeCmp1.Add(ed);
                    }
                    catch (Exception) { }
                }

                intEvts.Stop();

                sel.OnSelect   -= new SelectEventsSink_OnSelectEventHandler(select);
                key.OnKeyPress -= new KeyboardEventsSink_OnKeyPressEventHandler(keyOp);
                sel             = null;
                key             = null;
                intEvts         = null;
            }
            catch (Exception)
            {
                sel     = null;
                key     = null;
                intEvts = null;
            }
        }
예제 #5
0
        private void m_buttonDef_OnExecute(NameValueMap context)
        {
            if (m_dialog != null)
            {
                m_dialog.Focus();
                return;
            }

            m_interaction = m_inventorApplication.CommandManager.CreateInteractionEvents();
            m_interaction.StatusBarText = "Select the face to add tabs to";
            m_selects = m_interaction.SelectEvents;
            m_selects.ClearSelectionFilter();
            m_selects.AddSelectionFilter(SelectionFilterEnum.kPartFacePlanarFilter);
            //m_selects.SingleSelectEnabled = true;
            m_selects.MouseMoveEnabled = false; // recommended for performance if not used
            m_selects.Enabled          = true;  // ???
            // no idea what these event sinks are and why we need them...
            m_selects.OnSelect        += new Inventor.SelectEventsSink_OnSelectEventHandler(this.SelectEvents_OnSelect);
            m_interaction.OnTerminate += new Inventor.InteractionEventsSink_OnTerminateEventHandler(this.M_interaction_OnTerminate);



            // TODO: only do this once per document!
            // TODO: why doesn't it work at all??!?!
            m_browser_events = m_inventorApplication.ActiveDocument.BrowserPanes.BrowserPanesEvents;
            m_browser_events.OnBrowserNodeActivate  += new Inventor.BrowserPanesSink_OnBrowserNodeActivateEventHandler(this.BrowserPanesEvents_OnBrowserNodeActivate);
            m_browser_events.OnBrowserNodeLabelEdit += new Inventor.BrowserPanesSink_OnBrowserNodeLabelEditEventHandler(M_browser_events_OnBrowserNodeLabelEdit);

            m_dialog = new LaserTabForm(m_form_state);

            m_dialog.Show(new InventorMainFrame(m_inventorApplication.MainFrameHWND));
            m_dialog.FormClosed      += M_dialog_FormClosed;
            m_dialog.button_ok.Click += Button_ok_Click;

            m_interaction.Start();
        }
예제 #6
0
        private void frmSelection_Load(object sender, EventArgs e)
        {
            //�����µ�InteractionEvents����
            interaction = ThisApplication.CommandManager.CreateInteractionEvents();

            //������ʾ
            interaction.StatusBarText = "Select an edge.";

            //���ӵ���ص�ѡ���¼�
            select = interaction.SelectEvents;

            //�������е�����߶�����ѡ��
            select.AddSelectionFilter(SelectionFilterEnum.kPartEdgeFilter);

            //���õ�һѡ��
            select.SingleSelectEnabled = true;

            //��ʼѡ�����
            interaction.Start();

            //�¼���Ӧ
            select.OnSelect += new SelectEventsSink_OnSelectEventHandler(select_OnSelect);
            select.OnPreSelect += new SelectEventsSink_OnPreSelectEventHandler(select_OnPreSelect);
        }
예제 #7
0
 /// <summary>
 /// Enables select events when interaction events are activated.
 /// </summary>
 private void interactionEvents_OnActivate()
 {
     SelectEvents = InteractionEvents.SelectEvents;
     SelectEvents.AddSelectionFilter(SelectionFilterEnum.kAssemblyOccurrenceFilter);
     SelectEvents.OnSelect += selectEvents_OnSelect;
 }
예제 #8
0
 /// <summary>
 /// Enables select events when interaction events are activated.
 /// </summary>
 private void interactionEvents_OnActivate()
 {
     selectEvents = interactionEvents.SelectEvents;
     selectEvents.AddSelectionFilter(SelectionFilterEnum.kSketchPointFilter);
     selectEvents.OnSelect += selectEvents_OnSelect;
 }
예제 #9
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();
            }
        }