Esempio n. 1
0
        private bool check(FaceProxy f, double maxR)
        {
            if (f.SurfaceType != SurfaceTypeEnum.kCylinderSurface)
            {
                return(false);
            }
            Cylinder c = f.Geometry as Cylinder;

            if (c == null)
            {
                return(false);
            }
            Point pt = c.BasePoint.Copy();

            //pt.TranslateBy(c.AxisVector.AsVector());
            if (f.TangentiallyConnectedFaces.Count == 3)
            {
                if (c.Radius == 9.3 / 20 || c.Radius == 0.2)
                {
                    return(false);
                }
                slots.Add(new slot(f));
                return(false);
            }
            return(check(pt) && f.SurfaceType == SurfaceTypeEnum.kCylinderSurface && (f.CreatedByFeature is HoleFeatureProxy || f.CreatedByFeature is CutFeatureProxy ||
                                                                                      f.CreatedByFeature is ReferenceFeatureProxy ||
                                                                                      f.CreatedByFeature is PunchToolFeatureProxy || f.CreatedByFeature is MirrorFeatureProxy ||
                                                                                      f.CreatedByFeature is RectangularPatternFeatureProxy) &&
                   (f.TangentiallyConnectedFaces.Count == 3 || f.TangentiallyConnectedFaces.Count == 0) && ((Cylinder)f.Geometry).Radius < maxR);
        }
Esempio n. 2
0
        private List <EdgeProxy> findEdges()
        {
            if (faces.Count == 0)
            {
                return(null);
            }
            //FaceProxy face = faces.ElementAt(0);
            FaceProxy face = u.get <FaceProxy>(faces, fi => !except.Contains(fi));

            if (face == null)
            {
                return(null);
            }
            //except.Add(face);
            Cylinder   cylfind = face.Geometry as Cylinder;
            UnitVector vb      = cylfind.AxisVector;
            Point      ptb     = cylfind.BasePoint;
            bool       isHole  = true;

            if (face.TangentiallyConnectedFaces.Count == 3)
            {
                isHole = false;
            }
            List <EdgeProxy>        lst  = new List <EdgeProxy>();
            IEnumerable <FaceProxy> dist = null;

            dist = u.add <FaceProxy>(dist, face);
            if (face.Edges.Count == 2)
            {
                lst.AddRange(face.Edges.OfType <EdgeProxy>());
            }
            foreach (FaceProxy item in faces)
            {
                if (item.Equals(face))
                {
                    continue;
                }
                Cylinder c = item.Geometry as Cylinder;
                if (c == null)
                {
                    continue;
                }
                UnitVector v  = c.AxisVector;
                Point      pt = c.BasePoint;
                if (u.eq(ptb, vb, pt))
                {
                    if (item.Edges.Count == 2)
                    {
                        lst.AddRange(item.Edges.OfType <EdgeProxy>());
                    }
                    dist = u.add <FaceProxy>(dist, item);
//                     if (isHole && ptb.DistanceTo(pt) < 0.7)
//                         dist = u.add<Face>(dist, item);
//                     else
                    //except.Add(item);
                }
            }
            if (dist != null) /*faces = faces.Except(dist).ToList();*/ except {
Esempio n. 3
0
        public void addProject()
        {
            try
            {
                m_asmCompDef = asmDoc.ComponentDefinition;
                invApp       = (Inventor.Application)asmDoc.Parent;
                tg           = invApp.TransientGeometry;
                smcd         = (SheetMetalComponentDefinition)m_asmCompDef.Occurrences[1].Definition;
                SheetMetalComponentDefinition smcd2 = (SheetMetalComponentDefinition)m_asmCompDef.Occurrences[2].Definition;
                //m_asmCompDef.Occurrences[1].Edit();
                CommandManager cmdMgr = ((Inventor.Application)asmDoc.Parent).CommandManager;
                FaceProxy      face;
                object         obj = cmdMgr.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Выберите плоскость эскиза:");
                objCol = invApp.TransientObjects.CreateObjectCollection();
                face   = (FaceProxy)obj;
                asmDoc.SelectSet.Select(m_asmCompDef.Occurrences[2]);
                //((PartDocument)smcd.Document).SelectSet.Select(m_asmCompDef.Occurrences[2].CreateGeometryProxy());
                //double[] pts = {face.PointOnFace.X,face.PointOnFace.Y,face.PointOnFace.Z};
                //double[] normals = {0,0,0};
                //face.Evaluator.GetNormalAtPoint(ref pts, ref normals);
                //Plane pl = invApp.TransientGeometry.CreatePlane(face.PointOnFace, invApp.TransientGeometry.CreateVector(normals[0], normals[1], normals[2]));
                //obj = m_asmCompDef.Occurrences[2].Definition.SurfaceBodies[1];
                //m_PartDoc.SelectSet.Select()
                obj = null;
                WorkPlane wp = smcd2.WorkPlanes[3];
                m_asmCompDef.Occurrences[1].CreateGeometryProxy(face, out obj);
                FaceProxy face2 = (FaceProxy)obj;
                ps = smcd.Sketches.Add(face2);
                ProjectedCut cut = ps.ProjectedCuts.Add();
                PlanarSketch pls = smcd2.Sketches.Add(smcd2.WorkPlanes[3]);
                m_asmCompDef.Occurrences[2].CreateGeometryProxy(pls, out obj);
                psp = (PlanarSketchProxy)obj;
                foreach (var item in ps.SketchLines)
                {
                    m_asmCompDef.Occurrences[1].CreateGeometryProxy(item, out obj);
                    psp.AddByProjectingEntity(obj);
                }
                //m_asmCompDef.Occurrences[2].CreateGeometryProxy(smcd.WorkPlanes[3],out obj);
                //m_asmCompDef.Occurrences[1].CreateGeometryProxy(ps,out obj);

                //psp.ProjectedCuts.Add();
                TransientGeometry tr = invApp.TransientGeometry;
                //cmdMgr.ControlDefinitions["SketchProjectCutEdgesCmd"].Execute();
                //enumerat = invApp.TransientGeometry.SurfaceSurfaceIntersection(m_asmCompDef.Occurrences[2].Definition.SurfaceBodies[1], pl);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private void find(fastenerSource fast)
        {
            Occ.rev = 1;
            fast.create();
            if (fast.filter())
            {
                return;
            }
            if (fast.l.Length < 3)
            {
                return;
            }
            xml.setRoot();
            cont.setRoot();
            string nameAtt = "hole";

            if (fast.tf == typeFastener.slot)
            {
                nameAtt = "slot";
            }
            if (!xml.set(xml.getEl(new Dictionary <string, string>()
            {
                { "d1", u.convToString(fast.d.First(), 3, "##.##") }, { "d2", u.convToString(fast.d.Last(), 3, "##.##") }, { "name", nameAtt }
            }, false)))
            {
                return;
            }
            Occ      old = default(Occ); bool first = true; bool change = false;
            fastEdge ed = fast.fe;

            if (MyXML.getAtt(xml.elem, "rev") != "")
            {
                ed = fast.le;
            }
            if (contentCenter.check(ed.e as EdgeProxy))
            {
                return;
            }
            foreach (var item in xml.elem.Elements())
            {
                string v    = MyXML.getAtt(item, "val");
                string strL = MyXML.getAtt(item, "l");
                string r    = MyXML.getAtt(item, "rev");
                if (v == "")
                {
                    continue;
                }
                if (v == "rev")
                {
                    Occ.rev = -1; first = true; change = true; continue;
                }
                xml.setRoot();
                var spl = v.Split(':');
                xml.set("abbr", spl[0]);
                cont.set("name", MyXML.getAtt(xml.elem, "name"));
                int n = int.Parse(spl[1]) - 1;
                cont.set(n);
                string        name  = cont.getAtt("Id");
                contentCenter cc    = new contentCenter(doc as Document);
                Occ           co    = cc.place(name);
                string        fname = xml.getAtt("folder");
                addToFolder(co, fname);
                xml.setRoot();
                cont.setRoot();
                if ((spl[0] == "ГЗ" || spl[0] == "ГЗП") && !first)
                {
                    //co.dist = ls + lm;
                    if (strL == "" || !u.eq(strL, fast.l[1] * 10))
                    {
                        co.remove(); continue;
                    }
                    if (fast.fe.Equals(fast.e.First()))
                    {
                        Array.Reverse(fast.l);
                    }
                    double d    = -(fast.l[0] + fast.l[1]);
                    bool   axis = false;
                    if (r != "")
                    {
                        axis = !axis; d = fast.l.Sum();
                    }
                    if (nameAtt == "hole")
                    {
                        cc.add(ed.e, co, d, !axis);
                    }
                    else if (nameAtt == "slot")
                    {
                        fastenerSlot fs  = fast as fastenerSlot;
                        FaceProxy    fac = u.get <FaceProxy>(ed.e.Faces, fi => fi.SurfaceType == SurfaceTypeEnum.kPlaneSurface);
                        if (fac != null)
                        {
                            cc.add(fac, co, d, axis);
                        }
                        if (fs.fp != null)
                        {
                            cc.add(fs.fp, co);
                        }
                    }
                    continue;
                }
                double dist = 0;
                if (change)
                {
                    dist = co.dist;
                }
                if (first)
                {
                    if (change)
                    {
                        dist = (fast.l.Sum()) * Occ.rev + co.dist;
                    }
                    switch (fast.tf)
                    {
                    case typeFastener.hole:
                        cc.add(ed.e, co, dist);
                        break;

                    case typeFastener.slot:
                        fastenerSlot fs  = fast as fastenerSlot;
                        FaceProxy    fac = u.get <FaceProxy>(ed.e.Faces, fi => fi.SurfaceType == SurfaceTypeEnum.kPlaneSurface);
                        if (fac != null)
                        {
                            cc.add(fac, co, dist);
                        }
                        if (fs.fp != null)
                        {
                            cc.add(fs.fp, co);
                        }
                        break;

                    default:
                        break;
                    }
                    first = false; Occ.rev = -Occ.rev;
                }

                else
                {
                    cc.add(old, co, dist);
                }
                old = co;
            }
        }
Esempio n. 6
0
        private void createProxy(FaceProxy face, int num, ref object fac)
        {
            ComponentOccurrence occ = face.ContainingOccurrence;

            occ.CreateGeometryProxy(((PartComponentDefinition)occ.Definition).WorkPlanes[num], out fac);
        }