Пример #1
0
        public dynamic FabGetDBItem(ResultBuffer args)
        {
            ResultBuffer ret = new ResultBuffer();
            object       res = null;

            if (args != null)
            {
                TypedValue[] argarray = args.AsArray();
                ObjectId     ent;
                string       path    = "";
                string       varName = "";
                dynamic      itm     = null;
                if (argarray.Length >= 2)
                {
                    if (argarray.Length >= 1 && argarray[0].TypeCode == (int)LispDataType.ObjectId)
                    {
                        ent = (ObjectId)argarray[0].Value;
                        try
                        {
                            itm = Autodesk.Fabrication.Job.GetFabricationItemFromACADHandle(ent.Handle.ToString());
                        }
                        catch (System.Exception) { }
                    }
                    else if (argarray.Length >= 1 && argarray[0].TypeCode == (int)LispDataType.Text)
                    {
                        itm = (string)argarray[0].Value;
                        if (itm.StartsWith("$") == true && VarCache.ContainsKey(hand.VariableName(itm)) == true)
                        {
                            itm = VarCache[hand.VariableName(itm)];
                        }
                    }
                    if (argarray.Length >= 2 && argarray[1].TypeCode == (int)LispDataType.Text)
                    {
                        path = (string)argarray[1].Value;
                    }
                    if (argarray.Length >= 3 && argarray[2].TypeCode == (int)LispDataType.Text)
                    {
                        varName = hand.VariableName((string)argarray[2].Value);
                    }
                }
                if (itm != null && path.Length > 1)
                {
                    res = Sequencing.GenericPropertyGetter(itm, new List <string>(path.Split('.')));
                    if (varName.Length >= 1)
                    {
                        if (VarCache.ContainsKey(varName) == true)
                        {
                            VarCache[varName] = res;
                        }
                        else
                        {
                            VarCache.Add(varName, res);
                        }
                    }
                }
            }
            if (res != null)
            {
                foreach (TypedValue x in hand.ConvertToRB(res))
                {
                    ret.Add(x);
                }
            }
            else
            {
                ret.Add(new TypedValue((int)LispDataType.Nil));
            }
            if (ret.AsArray().Length > 1)
            {
                return(ret);
            }
            else
            {
                return(ret.AsArray()[0]);
            }
        }
Пример #2
0
        public object FabInvokeItem(ResultBuffer args)
        {
            ResultBuffer ret  = new ResultBuffer();
            dynamic      pres = null;
            dynamic      mres = null;

            Autodesk.AutoCAD.Geometry.Point3dCollection pts = new Autodesk.AutoCAD.Geometry.Point3dCollection();
            if (args != null)
            {
                TypedValue[]  argarray = args.AsArray();
                ObjectId      ent;
                string        path     = "";
                string        methName = "";
                string        varName  = "";
                List <object> methArgs = new List <object>();
                dynamic       itm      = null;
                if (argarray.Length >= 1 && argarray[0].TypeCode == (int)LispDataType.ObjectId)
                {
                    ent = (ObjectId)argarray[0].Value;
                    try
                    {
                        itm = Autodesk.Fabrication.Job.GetFabricationItemFromACADHandle(ent.Handle.ToString());
                        if (itm.Connectors?.Count >= 1)
                        {
                            Transaction tr  = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction();
                            DBObject    dbo = tr.GetObject((ObjectId)ent, OpenMode.ForRead);
                            (dbo as Entity).GetStretchPoints(pts);
                            tr.Dispose();
                        }
                    }
                    catch (System.Exception) { }
                }
                else if (argarray.Length >= 1 && argarray[0].TypeCode == (int)LispDataType.Text)
                {
                    itm = (string)argarray[0].Value;
                    if (itm.StartsWith("$") == true && VarCache.ContainsKey(hand.VariableName(itm)) == true)
                    {
                        itm = VarCache[hand.VariableName(itm)];
                    }
                }
                if (argarray.Length >= 2 && argarray[1].TypeCode == (int)LispDataType.Text)
                {
                    path = (string)argarray[1].Value;
                }
                if (argarray.Length >= 3 && argarray[2].TypeCode == (int)LispDataType.Text)
                {
                    methName = hand.VariableName((string)argarray[2].Value);
                }
                methArgs = hand.ExtractListValues(argarray);
                if (argarray[argarray.Length - 1].TypeCode == (int)LispDataType.Text)
                {
                    varName = hand.VariableName(hand.GetVarNameFromArgs(argarray[argarray.Length - 1]));
                }
                if (itm != null && path.Length > 1 && methName.Length >= 1)
                {
                    pres = Sequencing.GenericPropertyGetter(itm, new List <string>(path.Split('.')));
                    mres = Sequencing.GenericMethodInvoke(pres, methName, methArgs);
                    if (methName == "GETCONNECTORENDPOINT")
                    {
                        mres = pts.Count >= 1 ? pts : null;
                    }
                    if (varName.Length >= 1)
                    {
                        if (VarCache.ContainsKey(varName) == true)
                        {
                            VarCache[varName] = mres;
                        }
                        else
                        {
                            VarCache.Add(varName, mres);
                        }
                    }
                }
            }
            if (mres != null)
            {
                foreach (TypedValue x in hand.ConvertToRB(mres))
                {
                    ret.Add(x);
                }
                if (ret.AsArray().Length > 1)
                {
                    return(ret);
                }
                else
                {
                    return(ret.AsArray()[0]);
                }
            }
            else
            {
                return(true);
            }
        }