private static AxisDir MakeAxialDirection(int num, bool isNeg, DbElement pnt, DbElement modelEle)
		{
			Direction dir = ParseExperDir(pnt.GetAsString(DbAttributeInstance.PAXI), modelEle);
			double offset = EvalDouble(pnt.GetAsString(DbAttributeInstance.PDIS), modelEle);
			Position pos = Position.Create();
			pos.MoveBy(dir, offset);
			if (isNeg)
				dir = dir.Opposite();
			return new AxisDir(pos, dir);
		}
        private static AxisDir MakePositionTypeDirection(int num, bool isNeg, DbElement pnt, DbElement modelEle)
        {
            Direction dir = ParseExperDir(pnt.GetAsString(DbAttributeInstance.PTCD), modelEle);
            AxisDir   pos = Eval(modelEle, pnt.GetAsString(DbAttributeInstance.PTCPOS));

            if (isNeg)
            {
                dir = dir.Opposite();
            }
            return(new AxisDir(pos.Pos, dir));
        }
        private static AxisDir MakeAxialDirection(int num, bool isNeg, DbElement pnt, DbElement modelEle)
        {
            Direction dir    = ParseExperDir(pnt.GetAsString(DbAttributeInstance.PAXI), modelEle);
            double    offset = EvalDouble(pnt.GetAsString(DbAttributeInstance.PDIS), modelEle);
            Position  pos    = Position.Create();

            pos.MoveBy(dir, offset);
            if (isNeg)
            {
                dir = dir.Opposite();
            }
            return(new AxisDir(pos, dir));
        }
        private static AxisDir MakeMixedDirection(int num, bool isNeg, DbElement pnt, DbElement modelEle)
        {
            Direction dir = ParseExperDir(pnt.GetAsString(DbAttributeInstance.PAXI), modelEle);
            double    x   = EvalDouble(pnt.GetAsString(DbAttributeInstance.PX), modelEle);
            double    y   = EvalDouble(pnt.GetAsString(DbAttributeInstance.PY), modelEle);
            double    z   = EvalDouble(pnt.GetAsString(DbAttributeInstance.PZ), modelEle);

            if (isNeg)
            {
                dir = dir.Opposite();
            }
            return(new AxisDir(Position.Create(x, y, z), dir));
        }
Exemple #5
0
        public void ExportPipingItem(DbElement cur, ref List <IIfcProduct> elements)
        {
            new PipingItem(cur, string.Empty, this._mapping).ExportComponents(ref elements);
            string asString = cur.GetAsString((DbAttribute)DbAttributeInstance.NAME);

            HierarchyItem.Log.Info((object)("PIPE Exported: " + asString));
        }
Exemple #6
0
        private DbElement SDTE(DbElement cate, string detailText, string skey, DbElement equipment)
        {
            var       equiDesc = equipment.GetAsString(DbAttributeInstance.DESC);
            DbElement sdte     = DbElement.GetElement();

            if (equiDesc == "unset")
            {
                sdte = cate.Members().FirstOrDefault(m => m.ElementType == DbElementTypeInstance.SDTEXT);
                if (sdte == null || sdte.IsValid == false)
                {
                    sdte = cate.CreateLast(DbElementTypeInstance.SDTEXT);
                }
            }
            else
            {
                var sdteName = equipment.Name() + ".SDTE";
                sdte = cate.Members().FirstOrDefault(m => m.ElementType == DbElementTypeInstance.SDTEXT && m.Name() == sdteName);
                if (sdte == null || sdte.IsValid == false)
                {
                    sdte = cate.CreateLast(DbElementTypeInstance.SDTEXT);
                    try {
                        sdte.SetAttribute(DbAttributeInstance.NAME, sdteName);
                        Console.WriteLine("name error for sdte");
                    } catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }
                }
            }
            detailText = detailText.Replace("@SIZE", "' + STRING (PARA[1] ) + '");
            detailText = detailText.Replace("@DESC", equiDesc);
            PMLCommander.RunPMLCommand(sdte, "SKEY", $"'{skey}'", out var error);
            PMLCommander.RunPMLCommandInParentheses(sdte, "RTEXT", $"'{detailText}'", out error);
            Sdte = sdte;
            return(sdte);
        }
        private Experssion GetExper(DbElement gEle, DbAttribute attr)
        {
            Dictionary <string, Experssion> map = null;

            if (!experMap.TryGetValue(attr, out map))
            {
                map = new Dictionary <string, Experssion>();
                experMap.Add(attr, map);
            }

            Experssion exper = null;

            if (!map.TryGetValue(gEle.GetAsString(DbAttributeInstance.NAME), out exper))
            {
                exper = new Experssion(gEle.GetAsString(attr));
                map.Add(gEle.GetAsString(DbAttributeInstance.NAME), exper);
            }

            return(exper);
        }
Exemple #8
0
        static private string TeStCalculation(DbElement ele, DbAttribute att, DbQualifier qualifier)
        {
            // get Expression uda attribute
            var userDefinedAttributeExp = DbAttribute.GetDbAttribute(":uExpTest");
            var value = string.Empty;

            try
            {
                // evaluate attribute from :uExpTest to :uResultTest
                value = ele.EvaluateAsString(DbExpression.Parse(ele.GetAsString(userDefinedAttributeExp)));
            }
            catch (System.Exception)
            {
                value = "Default value";
            }

            // Result of UDA must be returned
            return(value);
        }
Exemple #9
0
        public void Configure_Model_Information()
        {
            try
            {
                foreach (KcsElementHandle handle in handler)
                {
                    try
                    {
                        KcsModel model = kcs_draft.ModelPropertiesGet(handle); //this can be only get  model handle. to get part handle, you have to use below method.
                        string   refno = kcs_draft.ElementDbrefGet(handle);
                        //KcsElementHandle viewhandle= kcs_draft.ViewIdentify(p1);
                        //string  viewdbref=kcs_draft.ElementPADDDbrefGet(viewhandle);

                        KcsModel m = new KcsModel();
                        m.Name = "=21184/1156";
                        kcs_draft.ModelDraw(m);

                        if (!models.Contains(model))
                        {
                            models.Add(model);

                            //DbElement dbelement = DbElement.GetElement(model.Name);
                            DbElement dbelement = DbElement.GetElement(refno);

                            dbelements.Add(dbelement);
                            kcs_ui.MessageNoConfirm(dbelement.GetAsString(DbAttributeInstance.FLNN));
                            kcs_ui.MessageNoConfirm(dbelement.Members().ToArray()[model.PartId].GetAsString(DbAttributeInstance.FLNN));
                        }
                    }catch (Exception ee)
                    {
                        kcs_ui.MessageNoConfirm("핸들을 모델로 변환중 에라 : " + handle.handle.ToString());
                    }
                }
            }catch (Exception ee)
            {
            }
        }
Exemple #10
0
        private void ExportPipeItem(DbElement ele, D3Transform transform, int color)
        {
            if (ele.GetElementType() == DbElementTypeInstance.TUBING)
            {
                ExportTube(ele, transform, color);
                return;
            }

            DbElement specEle = null;

            if ((specEle = ele.GetElement(DbAttributeInstance.SPRE)) == null ||
                !IsReadableEle(specEle) ||
                ele.GetElementType() == DbElementTypeInstance.ATTACHMENT
                )
            {
                return;;
            }

            DbElement cateEle = null;

            if ((cateEle = specEle.GetElement(DbAttributeInstance.CATR)) == null || !IsReadableEle(cateEle))
            {
                return;
            }

            DbElement gmEle = null;

            if ((gmEle = cateEle.GetElement(DbAttributeInstance.GMRE)) == null || !IsReadableEle(gmEle))
            {
                return;
            }

            D3Transform eleTrans = transform.Multiply(GetTransform(ele));

            DbElement gEle = gmEle.FirstMember();

            while (gEle != null && gEle.IsValid)
            {
                if (IsReadableEle(gEle) && gEle.GetBool(DbAttributeInstance.TUFL))
                {
                    if (!IsVisible(gEle))
                    {
                        gEle = gEle.Next();
                        continue;
                    }

                    try
                    {
                        if (gEle.GetElementType() == DbElementTypeInstance.SCYLINDER)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAXI);
                            AxisDir paxi = EvalDirection.Eval(ele, expr);

                            double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);
                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
                            double pdis = GetExper(gEle, DbAttributeInstance.PDIS).Eval(ele);

                            D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
                            D3Point  pos = eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos));

                            Cylinder cyl = new Cylinder();
                            cyl.Org = new Point(pos)
                                      .MoveBy(dir, pdis);
                            cyl.Height = new Point(dir).Mul(phei);
                            cyl.Radius = pdia / 2.0;
                            cyl.Color  = color;
                            session.Save(cyl);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.LCYLINDER)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAXI);
                            AxisDir paxi = EvalDirection.Eval(ele, expr);

                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
                            double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);
                            double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);

                            D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
                            D3Point  pos = eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos));

                            Cylinder cyl = new Cylinder();
                            cyl.Org = new Point(pos)
                                      .MoveBy(dir, pbdi);
                            cyl.Height = new Point(dir).Mul(ptdi - pbdi);
                            cyl.Radius = pdia / 2.0;
                            cyl.Color  = color;
                            session.Save(cyl);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.SBOX)
                        {
                            double pxlen = GetExper(gEle, DbAttributeInstance.PXLE).Eval(ele);
                            double pylen = GetExper(gEle, DbAttributeInstance.PYLE).Eval(ele);
                            double pzlen = GetExper(gEle, DbAttributeInstance.PZLE).Eval(ele);
                            double px    = GetExper(gEle, DbAttributeInstance.PX).Eval(ele);
                            double py    = GetExper(gEle, DbAttributeInstance.PY).Eval(ele);
                            double pz    = GetExper(gEle, DbAttributeInstance.PZ).Eval(ele);

                            Point xlen = new Point(eleTrans.Multiply(D3Vector.D3EAST));
                            Point ylen = new Point(eleTrans.Multiply(D3Vector.D3NORTH));
                            Point zlen = new Point(eleTrans.Multiply(D3Vector.D3UP));

                            Point pos = new Point(eleTrans.Multiply(GeometryUtility.Org));
                            pos.MoveBy(xlen, px - pxlen / 2.0).MoveBy(ylen, py - pylen / 2.0).MoveBy(zlen, pz - pzlen / 2.0);
                            xlen.Mul(pxlen);
                            ylen.Mul(pylen);
                            zlen.Mul(pzlen);

                            Box box = new Box();
                            box.Org   = pos;
                            box.XLen  = xlen;
                            box.YLen  = ylen;
                            box.ZLen  = zlen;
                            box.Color = color;
                            session.Save(box);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.SCTORUS)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAAX);
                            AxisDir paax = EvalDirection.Eval(ele, expr);

                            expr = gEle.GetAsString(DbAttributeInstance.PBAX);
                            AxisDir pbax = EvalDirection.Eval(ele, expr);

                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);

                            CircularTorus ct     = new CircularTorus();
                            Direction     normal = null;
                            if (!paax.Dir.IsParallel(pbax.Dir))
                            {
                                normal = paax.Dir.Orthogonal(pbax.Dir);
                            }
                            else
                            {
                                normal = paax.Dir.Orthogonal(Direction.Create(paax.Pos, pbax.Pos));
                            }
                            ct.Normal = new Point(eleTrans.Multiply(GeometryUtility.ToD3VectorRef(normal)));

                            ct.StartPnt    = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(pbax.Pos)));
                            ct.StartRadius = ct.EndRadius = pdia / 2.0;

                            double mRadius = 0.0;
                            if (!paax.Dir.IsParallel(pbax.Dir))
                            {
                                double ang = paax.Dir.Angle(pbax.Dir) * Math.PI / 180.0;
                                ct.Angle = Math.PI - ang;
                                ang     /= 2.0;
                                double len = paax.Pos.Distance(pbax.Pos) / 2;
                                mRadius = len / Math.Sin(ang) * Math.Tan(ang);
                            }
                            else
                            {
                                ct.Angle = Math.PI;
                                mRadius  = paax.Pos.Distance(pbax.Pos) / 2.0;
                            }
                            D3Vector radiusDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir.Orthogonal(normal)));
                            ct.Center = new Point(ct.StartPnt).MoveBy(radiusDir, mRadius);
                            ct.Color  = color;

                            session.Save(ct);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.SRTORUS)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAAX);
                            AxisDir paax = EvalDirection.Eval(ele, expr);

                            expr = gEle.GetAsString(DbAttributeInstance.PBAX);
                            AxisDir pbax = EvalDirection.Eval(ele, expr);

                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
                            double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);

                            RectangularTorus rt     = new RectangularTorus();
                            Direction        normal = null;
                            if (!paax.Dir.IsParallel(pbax.Dir))
                            {
                                normal = paax.Dir.Orthogonal(pbax.Dir);
                            }
                            else
                            {
                                normal = paax.Dir.Orthogonal(Direction.Create(paax.Pos, pbax.Pos));
                            }
                            rt.Normal = new Point(eleTrans.Multiply(GeometryUtility.ToD3VectorRef(normal)));

                            rt.StartPnt    = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(pbax.Pos)));
                            rt.StartWidth  = rt.EndWidth = pdia;
                            rt.StartHeight = rt.EndHeight = phei;

                            double mRadius = 0.0;
                            if (!paax.Dir.IsParallel(pbax.Dir))
                            {
                                double ang = paax.Dir.Angle(pbax.Dir) * Math.PI / 180.0;
                                rt.Angle = Math.PI - ang;
                                ang     /= 2.0;
                                double len = paax.Pos.Distance(pbax.Pos) / 2;
                                mRadius = len / Math.Sin(ang) * Math.Tan(ang);
                            }
                            else
                            {
                                rt.Angle = Math.PI;
                                mRadius  = paax.Pos.Distance(pbax.Pos) / 2.0;
                            }
                            D3Vector radiusDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir.Orthogonal(normal)));
                            rt.Center = new Point(rt.StartPnt).MoveBy(radiusDir, mRadius);
                            rt.Color  = color;

                            session.Save(rt);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.LSNOUT)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAAX);
                            AxisDir paax = EvalDirection.Eval(ele, expr);

                            expr = gEle.GetAsString(DbAttributeInstance.PBAX);
                            AxisDir pbax = EvalDirection.Eval(ele, expr);

                            double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);
                            double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);
                            double ptdm = GetExper(gEle, DbAttributeInstance.PTDM).Eval(ele);
                            double pbdm = GetExper(gEle, DbAttributeInstance.PBDM).Eval(ele);
                            double poff = GetExper(gEle, DbAttributeInstance.POFF).Eval(ele);

                            D3Vector tdir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paax.Dir));
                            D3Point  pos  = eleTrans.Multiply(GeometryUtility.ToD3Point(paax.Pos));
                            D3Vector bdir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir));

                            if (pbdm < 1.0e-5 || ptdm < 1.0e-5)
                            {
                                Cone cone = new Cone();
                                cone.Radius = pbdm > ptdm ? pbdm / 2.0 : ptdm / 2.0;
                                cone.Org    = new Point(pos).MoveBy(tdir, pbdi);
                                cone.Offset = new Point(bdir).Mul(poff);
                                cone.Height = new Point(tdir).Mul(ptdi - pbdi);
                                cone.Color  = color;
                                session.Save(cone);
                            }
                            else
                            {
                                Snout snout = new Snout();
                                snout.BottomRadius = pbdm / 2.0;
                                snout.TopRadius    = ptdm / 2.0;
                                snout.Org          = new Point(pos).MoveBy(tdir, pbdi);
                                snout.Offset       = new Point(bdir).Mul(poff);
                                snout.Height       = new Point(tdir).Mul(ptdi - pbdi);
                                snout.Color        = color;
                                session.Save(snout);
                            }
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.SDSH)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAXI);
                            AxisDir paxi = EvalDirection.Eval(ele, expr);

                            double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);
                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
                            double pdis = GetExper(gEle, DbAttributeInstance.PDIS).Eval(ele);
                            double prad = GetExper(gEle, DbAttributeInstance.PRAD).Eval(ele);

                            D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
                            if (prad > 0.0)
                            {
                                Ellipsoid ellipsoid = new Ellipsoid();
                                ellipsoid.Center = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos)))
                                                   .MoveBy(dir, pdis);
                                ellipsoid.ALen    = new Point(dir).Mul(phei);
                                ellipsoid.BRadius = pdia / 2.0;
                                ellipsoid.Color   = color;
                                session.Save(ellipsoid);
                            }
                            else
                            {
                                Sphere sphere = new Sphere();
                                sphere.Center = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos)))
                                                .MoveBy(dir, pdis);
                                double bottomRadius = pdia / 2.0;
                                sphere.Radius       = (bottomRadius * bottomRadius + phei * phei) / 2.0 / phei;
                                sphere.BottomNormal = new Point(-dir);
                                double angle = Math.PI / 2.0 - Math.Asin(2.0 * bottomRadius * phei / (bottomRadius * bottomRadius + phei * phei));
                                if (bottomRadius >= phei)
                                {
                                    sphere.Angle = Math.PI - angle * 2.0;
                                }
                                else
                                {
                                    sphere.Angle = Math.PI + angle * 2.0;
                                }
                                sphere.Color = color;
                                session.Save(sphere);
                            }
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.LPYRAMID)
                        {
                            string  exper = gEle.GetAsString(DbAttributeInstance.PAAX);
                            AxisDir paax  = EvalDirection.Eval(ele, exper);
                            exper = gEle.GetAsString(DbAttributeInstance.PBAX);
                            AxisDir pbax = EvalDirection.Eval(ele, exper);
                            exper = gEle.GetAsString(DbAttributeInstance.PCAX);
                            AxisDir pcax = EvalDirection.Eval(ele, exper);

                            double pbtp = GetExper(gEle, DbAttributeInstance.PBTP).Eval(ele);
                            double pctp = GetExper(gEle, DbAttributeInstance.PCTP).Eval(ele);
                            double pbbt = GetExper(gEle, DbAttributeInstance.PBBT).Eval(ele);
                            double pcbt = GetExper(gEle, DbAttributeInstance.PCBT).Eval(ele);
                            double pbof = GetExper(gEle, DbAttributeInstance.PBOF).Eval(ele);
                            double pcof = GetExper(gEle, DbAttributeInstance.PCOF).Eval(ele);
                            double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);
                            double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);

                            D3Vector zDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paax.Dir));
                            D3Vector xDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir));
                            D3Vector yDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pcax.Dir));
                            D3Point  org  = eleTrans.Multiply(GeometryUtility.ToD3Point(paax.Pos));
                            org.MoveBy(zDir * pbdi);

                            double height = ptdi - pbdi;

                            Pyramid pyramid = new Pyramid();
                            pyramid.Org        = new Point(org);
                            pyramid.Height     = new Point(zDir).Mul(height);
                            pyramid.XAxis      = new Point(xDir);
                            pyramid.BottomXLen = pbbt;
                            pyramid.BottomYLen = pcbt;
                            pyramid.TopXLen    = pbtp;
                            pyramid.TopYLen    = pctp;
                            pyramid.Offset     = new Point(xDir * pbof + yDir * pcof);
                            pyramid.Color      = color;
                            session.Save(pyramid);
                        }
                    }
                    catch (System.NullReferenceException)
                    {
                    }
                    catch (System.Exception)
                    {
                        System.Console.WriteLine("Ele = " + ele.GetAsString(DbAttributeInstance.NAME));
                        System.Console.WriteLine("GEle = " + gEle.GetAsString(DbAttributeInstance.NAME));
                        throw;
                    }
                }
                gEle = gEle.Next();
            }
        }
Exemple #11
0
        public void reculsive_copy_spec(DbElement owner, DbElement copy_from_element, string specname, List <int> diameters)
        {
            try {
                int           ddepth         = copy_from_element.GetInteger(DbAttributeInstance.DDEP);
                DbElementType copy_from_type = copy_from_element.GetElementType(DbAttributeInstance.TYPE);
                if (copy_from_type == DbElementTypeInstance.TEXT)
                {
                    return;
                }
                string copy_from_name = copy_from_element.GetAsString(DbAttributeInstance.NAME);
                string tanswer        = copy_from_element.GetAsString(DbAttributeInstance.TANS);


                //if (copy_from_type == DbElementTypeInstance.SPCOMPONENT)
                //return;
                //if (ddepth == 6)
                //    return;
                DbElement sel = null;
                if (ddepth == 3) //comp 타입 결정
                {
                    string type_name = "/" + specname + "." + tanswer;
                    try {
                        var selobj = owner.Members().Where(x => x.GetAsString(DbAttributeInstance.NAME) == type_name);

                        if (selobj.Count() == 0)
                        {
                            sel = owner.CreateLast(copy_from_type);
                            sel.SetAttribute(DbAttributeInstance.NAME, type_name);
                            sel.Copy(copy_from_element);
                        }
                        else
                        {
                            sel = selobj.First();
                        }
                        foreach (DbElement org in copy_from_element.Members())
                        {
                            reculsive_copy_spec(sel, org, specname, diameters);
                        }
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine("해당 Selec는 존재하기에 오류남");
                        Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(string.Format("$p |{0} Selec는 존재하기에 오류남222|", type_name)).RunInPdms();
                    }
                }

                else
                {
                    if (ddepth == 4)
                    {
                        int size = Convert.ToInt32(copy_from_element.GetAsString(DbAttributeInstance.ANSW).Replace("mm", ""));
                        if (!diameters.Contains(size))
                        {
                            return;
                        }
                        //if (size != 32)
                        Console.WriteLine("11");
                    }
                    //sel = owner.CreateLast(DbElementTypeInstance.SELEC);
                    if (tanswer.Contains("JOINT-MITRE") || tanswer.Contains("JOINT-THREAD"))
                    {
                        return;
                    }
                    if (copy_from_name == "/PPPG40S/HMDP_SPEC/PEPG409SS-25")
                    {
                        //return;
                        Console.WriteLine("11");
                    }
                    sel = owner.CreateLast(copy_from_type);
                    if (copy_from_type == DbElementTypeInstance.SPCOMPONENT)
                    {
                        //spco이름 세팅
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.NAME, "/" + specname + copy_from_element.GetAsString(DbAttributeInstance.CATR).Replace("-SCOM", ""));
                        }catch (Exception ee)
                        {
                        }

                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.CMPR, copy_from_element.GetElement(DbAttributeInstance.CMPR));
                        }
                        catch (Exception ee) { }
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.CATR, copy_from_element.GetElement(DbAttributeInstance.CATR));
                        }
                        catch (Exception ee) { }
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.DETR, copy_from_element.GetElement(DbAttributeInstance.DETR));
                        }
                        catch (Aveva.Pdms.Utilities.Messaging.PdmsException ee) {
                        }
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.PRTREF, copy_from_element.GetElement(DbAttributeInstance.PRTREF));
                        }catch (Exception ee)
                        { }
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.TANS, copy_from_element.GetAsString(DbAttributeInstance.TANS));
                        }
                        catch (Exception ee) { }
                    }
                    else
                    {
                        sel.Copy(copy_from_element);
                    }

                    foreach (DbElement org in copy_from_element.Members())
                    {
                        reculsive_copy_spec(sel, org, specname, diameters);
                    }
                }
            }
            catch (Exception ee)
            {
                Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(string.Format("$p |{0} any is wrong|", "--")).RunInPdms();
            }


            //DbCopyOption op = new DbCopyOption();
            //sel.CopyHierarchy(copy_from_element, op);

            //reculsive_copy_spec()
        }
		private void ExportPipeItem(DbElement ele, D3Transform transform, int color)
		{
			if (ele.GetElementType() == DbElementTypeInstance.TUBING)
			{
				ExportTube(ele, transform, color);
				return;
			}

			DbElement specEle = null;
			if ((specEle = ele.GetElement(DbAttributeInstance.SPRE)) == null
				|| !IsReadableEle(specEle)
				|| ele.GetElementType() == DbElementTypeInstance.ATTACHMENT
				)
			{
				return; ;
			}

			DbElement cateEle = null;
			if ((cateEle = specEle.GetElement(DbAttributeInstance.CATR)) == null || !IsReadableEle(cateEle))
			{
				return;
			}

			DbElement gmEle = null;
			if ((gmEle = cateEle.GetElement(DbAttributeInstance.GMRE)) == null || !IsReadableEle(gmEle))
			{
				return;
			}

			D3Transform eleTrans = transform.Multiply(GetTransform(ele));

			DbElement gEle = gmEle.FirstMember();
			while (gEle != null && gEle.IsValid)
			{
				if (IsReadableEle(gEle) && gEle.GetBool(DbAttributeInstance.TUFL))
				{
					if (!IsVisible(gEle))
					{
						gEle = gEle.Next();
						continue;
					}

					try
					{
						if (gEle.GetElementType() == DbElementTypeInstance.SCYLINDER)
						{
							string expr = gEle.GetAsString(DbAttributeInstance.PAXI);
							AxisDir paxi = EvalDirection.Eval(ele, expr);
	
							double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);
							double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
							double pdis = GetExper(gEle, DbAttributeInstance.PDIS).Eval(ele);
	
							D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
							D3Point pos = eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos));
	
							Cylinder cyl = new Cylinder();
							cyl.Org = new Point(pos)
								.MoveBy(dir, pdis);
							cyl.Height = new Point(dir).Mul(phei);
							cyl.Radius = pdia / 2.0;
							cyl.Color = color;
							session.Save(cyl);
						}
						else if (gEle.GetElementType() == DbElementTypeInstance.LCYLINDER)
						{
							string expr = gEle.GetAsString(DbAttributeInstance.PAXI);
							AxisDir paxi = EvalDirection.Eval(ele, expr);
	
							double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
							double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);
							double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);
	
							D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
							D3Point pos = eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos));
			
							Cylinder cyl = new Cylinder();
							cyl.Org = new Point(pos)
								.MoveBy(dir, pbdi);
							cyl.Height = new Point(dir).Mul(ptdi - pbdi);
							cyl.Radius = pdia / 2.0;
							cyl.Color = color;
							session.Save(cyl);
						}
						else if (gEle.GetElementType() == DbElementTypeInstance.SBOX)
						{
							double pxlen = GetExper(gEle, DbAttributeInstance.PXLE).Eval(ele);
							double pylen = GetExper(gEle, DbAttributeInstance.PYLE).Eval(ele);
							double pzlen = GetExper(gEle, DbAttributeInstance.PZLE).Eval(ele);
							double px = GetExper(gEle, DbAttributeInstance.PX).Eval(ele);
							double py = GetExper(gEle, DbAttributeInstance.PY).Eval(ele);
							double pz = GetExper(gEle, DbAttributeInstance.PZ).Eval(ele);
	
							Point xlen = new Point(eleTrans.Multiply(D3Vector.D3EAST));
							Point ylen = new Point(eleTrans.Multiply(D3Vector.D3NORTH));
							Point zlen = new Point(eleTrans.Multiply(D3Vector.D3UP));
	
							Point pos = new Point(eleTrans.Multiply(GeometryUtility.Org));
							pos.MoveBy(xlen, px - pxlen / 2.0).MoveBy(ylen, py - pylen / 2.0).MoveBy(zlen, pz - pzlen / 2.0);
							xlen.Mul(pxlen);
							ylen.Mul(pylen);
							zlen.Mul(pzlen);
	
							Box box = new Box();
							box.Org = pos;
							box.XLen = xlen;
							box.YLen = ylen;
							box.ZLen = zlen;
							box.Color = color;
							session.Save(box);
						}
						else if (gEle.GetElementType() == DbElementTypeInstance.SCTORUS)
						{
							string expr = gEle.GetAsString(DbAttributeInstance.PAAX);
							AxisDir paax = EvalDirection.Eval(ele, expr);
	
							expr = gEle.GetAsString(DbAttributeInstance.PBAX);
							AxisDir pbax = EvalDirection.Eval(ele, expr);
	
							double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
	
							CircularTorus ct = new CircularTorus();
							Direction normal = null;
							if (!paax.Dir.IsParallel(pbax.Dir))
								normal = paax.Dir.Orthogonal(pbax.Dir);
							else
								normal = paax.Dir.Orthogonal(Direction.Create(paax.Pos, pbax.Pos));
							ct.Normal = new Point(eleTrans.Multiply(GeometryUtility.ToD3VectorRef(normal)));
	
							ct.StartPnt = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(pbax.Pos)));
							ct.StartRadius = ct.EndRadius = pdia / 2.0;
	
							double mRadius = 0.0;
							if (!paax.Dir.IsParallel(pbax.Dir))
							{
								double ang = paax.Dir.Angle(pbax.Dir) * Math.PI / 180.0;
								ct.Angle = Math.PI - ang;
								ang /= 2.0;
								double len = paax.Pos.Distance(pbax.Pos) / 2;
								mRadius = len / Math.Sin(ang) * Math.Tan(ang);
	
							}
							else
							{
								ct.Angle = Math.PI;
								mRadius = paax.Pos.Distance(pbax.Pos) / 2.0;
							}
							D3Vector radiusDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir.Orthogonal(normal)));
							ct.Center = new Point(ct.StartPnt).MoveBy(radiusDir, mRadius);
							ct.Color = color;
	
							session.Save(ct);
						}
						else if (gEle.GetElementType() == DbElementTypeInstance.SRTORUS)
						{
							string expr = gEle.GetAsString(DbAttributeInstance.PAAX);
							AxisDir paax = EvalDirection.Eval(ele, expr);
	
							expr = gEle.GetAsString(DbAttributeInstance.PBAX);
							AxisDir pbax = EvalDirection.Eval(ele, expr);
	
							double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
							double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);
	
							RectangularTorus rt = new RectangularTorus();
							Direction normal = null;
							if (!paax.Dir.IsParallel(pbax.Dir))
								normal = paax.Dir.Orthogonal(pbax.Dir);
							else
								normal = paax.Dir.Orthogonal(Direction.Create(paax.Pos, pbax.Pos));
							rt.Normal = new Point(eleTrans.Multiply(GeometryUtility.ToD3VectorRef(normal)));
	
							rt.StartPnt = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(pbax.Pos)));
							rt.StartWidth = rt.EndWidth = pdia;
							rt.StartHeight = rt.EndHeight = phei;
	
							double mRadius = 0.0;
							if (!paax.Dir.IsParallel(pbax.Dir))
							{
								double ang = paax.Dir.Angle(pbax.Dir) * Math.PI / 180.0;
								rt.Angle = Math.PI - ang;
								ang /= 2.0;
								double len = paax.Pos.Distance(pbax.Pos) / 2;
								mRadius = len / Math.Sin(ang) * Math.Tan(ang);
	
							}
							else
							{
								rt.Angle = Math.PI;
								mRadius = paax.Pos.Distance(pbax.Pos) / 2.0;
							}
							D3Vector radiusDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir.Orthogonal(normal)));
							rt.Center = new Point(rt.StartPnt).MoveBy(radiusDir, mRadius);
							rt.Color = color;
	
							session.Save(rt);
						}
						else if (gEle.GetElementType() == DbElementTypeInstance.LSNOUT)
						{
							string expr = gEle.GetAsString(DbAttributeInstance.PAAX);
							AxisDir paax = EvalDirection.Eval(ele, expr);
	
							expr = gEle.GetAsString(DbAttributeInstance.PBAX);
							AxisDir pbax = EvalDirection.Eval(ele, expr);
	
							double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);
							double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);
							double ptdm = GetExper(gEle, DbAttributeInstance.PTDM).Eval(ele);
							double pbdm = GetExper(gEle, DbAttributeInstance.PBDM).Eval(ele);
							double poff = GetExper(gEle, DbAttributeInstance.POFF).Eval(ele);

							D3Vector tdir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paax.Dir));
							D3Point pos = eleTrans.Multiply(GeometryUtility.ToD3Point(paax.Pos));
							D3Vector bdir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir));
	
							if (pbdm < 1.0e-5 || ptdm < 1.0e-5)
							{
								Cone cone = new Cone();
								cone.Radius = pbdm > ptdm ? pbdm / 2.0 : ptdm / 2.0;
								cone.Org = new Point(pos).MoveBy(tdir, pbdi);
								cone.Offset = new Point(bdir).Mul(poff);
								cone.Height = new Point(tdir).Mul(ptdi - pbdi);
								cone.Color = color;
								session.Save(cone);
							}
							else
							{
								Snout snout = new Snout();
								snout.BottomRadius = pbdm / 2.0;
								snout.TopRadius = ptdm / 2.0;
								snout.Org = new Point(pos).MoveBy(tdir, pbdi);
								snout.Offset = new Point(bdir).Mul(poff);
								snout.Height = new Point(tdir).Mul(ptdi - pbdi);
								snout.Color = color;
								session.Save(snout);
							}
						}
						else if (gEle.GetElementType() == DbElementTypeInstance.SDSH)
						{
							string expr = gEle.GetAsString(DbAttributeInstance.PAXI);
							AxisDir paxi = EvalDirection.Eval(ele, expr);
	
							double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);
							double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
							double pdis = GetExper(gEle, DbAttributeInstance.PDIS).Eval(ele);
							double prad = GetExper(gEle, DbAttributeInstance.PRAD).Eval(ele);
	
							D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
							if (prad > 0.0)
							{
								Ellipsoid ellipsoid = new Ellipsoid();
								ellipsoid.Center = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos)))
									.MoveBy(dir, pdis);
								ellipsoid.ALen = new Point(dir).Mul(phei);
								ellipsoid.BRadius = pdia / 2.0;
								ellipsoid.Color = color;
								session.Save(ellipsoid);
							}
							else
							{
								Sphere sphere = new Sphere();
								sphere.Center = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos)))
									.MoveBy(dir, pdis);
								double bottomRadius = pdia / 2.0;
								sphere.Radius = (bottomRadius * bottomRadius + phei * phei) / 2.0 / phei;
								sphere.BottomNormal = new Point(-dir);
								double angle = Math.PI / 2.0 - Math.Asin(2.0 * bottomRadius * phei / (bottomRadius * bottomRadius + phei * phei));
								if (bottomRadius >= phei)
									sphere.Angle = Math.PI - angle * 2.0;
								else
									sphere.Angle = Math.PI + angle * 2.0;
								sphere.Color = color;
								session.Save(sphere);
							}
						}
						else if (gEle.GetElementType() == DbElementTypeInstance.LPYRAMID)
						{
							string exper = gEle.GetAsString(DbAttributeInstance.PAAX);
							AxisDir paax = EvalDirection.Eval(ele, exper);
							exper = gEle.GetAsString(DbAttributeInstance.PBAX);
							AxisDir pbax = EvalDirection.Eval(ele, exper);
							exper = gEle.GetAsString(DbAttributeInstance.PCAX);
							AxisDir pcax = EvalDirection.Eval(ele, exper);
	
							double pbtp = GetExper(gEle, DbAttributeInstance.PBTP).Eval(ele);
							double pctp = GetExper(gEle, DbAttributeInstance.PCTP).Eval(ele);
							double pbbt = GetExper(gEle, DbAttributeInstance.PBBT).Eval(ele);
							double pcbt = GetExper(gEle, DbAttributeInstance.PCBT).Eval(ele);
							double pbof = GetExper(gEle, DbAttributeInstance.PBOF).Eval(ele);
							double pcof = GetExper(gEle, DbAttributeInstance.PCOF).Eval(ele);
							double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);
							double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);
	
							D3Vector zDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paax.Dir));
							D3Vector xDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir));
							D3Vector yDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pcax.Dir));
							D3Point org = eleTrans.Multiply(GeometryUtility.ToD3Point(paax.Pos));
							org.MoveBy(zDir * pbdi);
	
							double height = ptdi - pbdi;
	
							Pyramid pyramid = new Pyramid();
							pyramid.Org = new Point(org);
							pyramid.Height = new Point(zDir).Mul(height);
							pyramid.XAxis = new Point(xDir);
							pyramid.BottomXLen = pbbt;
							pyramid.BottomYLen = pcbt;
							pyramid.TopXLen = pbtp;
							pyramid.TopYLen = pctp;
							pyramid.Offset = new Point(xDir * pbof + yDir * pcof);
							pyramid.Color = color;
							session.Save(pyramid);
						}
					}
					catch (System.NullReferenceException )
					{
						
					}
					catch (System.Exception)
					{
						System.Console.WriteLine("Ele = " + ele.GetAsString(DbAttributeInstance.NAME));
						System.Console.WriteLine("GEle = " + gEle.GetAsString(DbAttributeInstance.NAME));
						throw;
					}
				}
				gEle = gEle.Next();
			}
		}
		private Experssion GetExper(DbElement gEle, DbAttribute attr)
		{
			Dictionary<string, Experssion> map = null;
			if (!experMap.TryGetValue(attr, out map))
			{
				map = new Dictionary<string, Experssion>();
				experMap.Add(attr, map);
			}

			Experssion exper = null;
			if (!map.TryGetValue(gEle.GetAsString(DbAttributeInstance.NAME), out exper))
			{
				exper = new Experssion(gEle.GetAsString(attr));
				map.Add(gEle.GetAsString(DbAttributeInstance.NAME), exper);
			}

			return exper;
		}
		private static AxisDir MakeMixedDirection(int num, bool isNeg, DbElement pnt, DbElement modelEle)
		{
			Direction dir = ParseExperDir(pnt.GetAsString(DbAttributeInstance.PAXI), modelEle);
			double x = EvalDouble(pnt.GetAsString(DbAttributeInstance.PX), modelEle);
			double y = EvalDouble(pnt.GetAsString(DbAttributeInstance.PY), modelEle);
			double z = EvalDouble(pnt.GetAsString(DbAttributeInstance.PZ), modelEle);
			if (isNeg)
				dir = dir.Opposite();
			return new AxisDir(Position.Create(x, y, z), dir);
		}
		private static AxisDir MakePositionTypeDirection(int num, bool isNeg, DbElement pnt, DbElement modelEle)
		{
			Direction dir = ParseExperDir(pnt.GetAsString(DbAttributeInstance.PTCD), modelEle);
			AxisDir pos = Eval(modelEle, pnt.GetAsString(DbAttributeInstance.PTCPOS));
			if (isNeg)
				dir = dir.Opposite();
			return new AxisDir(pos.Pos, dir);
		}