Ejemplo n.º 1
0
        private string GetPropertiesLocal(string filePath)
        {
            string result = "";

            try
            {
                Inv.ApprenticeServerComponent asc = new Inv.ApprenticeServerComponent();
                Inv.ApprenticeServerDocument  asd = asc.Open(filePath);

                // "Inventor Summary Information"
                Inv.PropertySet ps = asd
                                     .PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"];

                foreach (Inv.Property p in ps)
                {
                    result += string.Format("{0}={1};",
                                            p.DisplayName,
                                            p.Value);
                }

                asd.Close();
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return(result);
        }
Ejemplo n.º 2
0
 private static void RemoveProperty(Inventor.PropertySet set, string name)
 {
     // Inventor API provides no easy way to check if a property already exists. This try-catch is necessary.
     try
     {
         // Try to add new property. This will result in an exception if the property already exists.
         set[name].Delete();
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 3
0
 private static void SetProperty <T>(Inventor.PropertySet set, string name, T value)
 {
     // Inventor API provides no easy way to check if a property already exists. This try-catch is necessary.
     try
     {
         // Try to add new property. This will result in an exception if the property already exists.
         set.Add(value, name);
     }
     catch (ArgumentException)
     {
         // Property already exists, update value
         set[name].Value = value;
     }
 }
Ejemplo n.º 4
0
 private static bool HasProperty(Inventor.PropertySet set, string name)
 {
     // Inventor API provides no easy way to check if a property already exists. This try-catch is necessary.
     try
     {
         // Try to add new property. This will result in an exception if the property already exists.
         set[name].Value = 0;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
 private static T GetProperty <T>(Inventor.PropertySet set, string name, T defaultValue)
 {
     // Inventor API provides no easy way to check if a property already exists. This try-catch is necessary.
     try
     {
         // Try to add new property with default value. This will result in an exception if the property already exists.
         set.Add(defaultValue, name);
         return(defaultValue);
     }
     catch (ArgumentException)
     {
         // Property already exists, get existing value
         return((T)set[name].Value);
     }
 }
Ejemplo n.º 6
0
        public static void Save(AssemblyDocument document, FieldProperties fieldProps, List <PropertySet> propertySets)
        {
            Inventor.PropertySets inventorPropertySets = document.PropertySets;

            try
            {
                Inventor.PropertySet p = GetPropertySet(inventorPropertySets, "synthesisField");

                // Field Properties
                SetProperty(p, "spawnpoints", JsonConvert.SerializeObject(fieldProps.spawnpoints));
                SetProperty(p, "gamepieces", JsonConvert.SerializeObject(fieldProps.gamepieces));

                // Property Sets
                SetProperty(p, "propertySets", JsonConvert.SerializeObject(propertySets, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                }));

                // Occurrences
                for (int i = 0; i < propertySets.Count; i++)
                {
                    var tabPage = (Components.ComponentPropertiesTabPage)Program.MAINWINDOW.GetPropertySetsTabControl().TabPages[propertySets[i].PropertySetID];

                    if (tabPage != null)
                    {
                        Components.InventorTreeView treeView = tabPage.ChildForm.inventorTreeView;
                        List <string> occurrences            = new List <string>();
                        foreach (TreeNode node in treeView.Nodes)
                        {
                            CreateOccurrenceList(node, "", occurrences);
                        }

                        SetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", JsonConvert.SerializeObject(occurrences));
                    }
                    else
                    {
                        SetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", "[]");
                    }
                }
            }
            catch (Exception e)
            {
                throw new FailedToSaveException(e);
            }
        }
Ejemplo n.º 7
0
        public static void Load(AssemblyDocument document, out FieldProperties fieldProps, out List <PropertySet> propertySets, out Dictionary <string, List <string> > occurrencePropSets)
        {
            Inventor.PropertySets inventorPropertySets = document.PropertySets;

            try
            {
                Inventor.PropertySet p = GetPropertySet(inventorPropertySets, "synthesisField");

                // Field Properties
                BXDVector3[] spawnpoints = JsonConvert.DeserializeObject <BXDVector3[]>(GetProperty(p, "spawnpoints", "[]"));
                if (spawnpoints == null)
                {
                    spawnpoints = new BXDVector3[0];
                }

                Gamepiece[] gamepieces = JsonConvert.DeserializeObject <Gamepiece[]>(GetProperty(p, "gamepieces", "[]"));
                if (gamepieces == null)
                {
                    gamepieces = new Gamepiece[0];
                }

                fieldProps = new FieldProperties(spawnpoints, gamepieces);

                // Property Sets
                propertySets = JsonConvert.DeserializeObject <List <PropertySet> >(GetProperty(p, "propertySets", "[]"), new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                });

                // Occurrences
                occurrencePropSets = new Dictionary <string, List <string> >();

                for (int i = 0; i < propertySets.Count(); i++)
                {
                    occurrencePropSets.Add(propertySets[i].PropertySetID,
                                           JsonConvert.DeserializeObject <List <string> >(GetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", "[]")));
                }
            }
            catch (Exception e)
            {
                throw new FailedToLoadException(e);
            }
        }
Ejemplo n.º 8
0
        private void DrawPartDoc(string filename)
        {
            DrawingDocument oDoc;
            Sheet           oSheet;

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            SetupNewDrawingDocument(out oDoc, out oSheet);
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Open the part document, invisibly.
            PartDocument      oBlockPart = mApp.Documents.Open(filename, false) as PartDocument;
            TransientGeometry oTG        = mApp.TransientGeometry;

            //0.1 = 1:10 or 0.2 = 1:5 1:20=0.02   X-> Y ^
            DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oBlockPart as _Document,
                                                                    oTG.CreatePoint2d(28.7, 21), 0.1,
                                                                    ViewOrientationTypeEnum.kFrontViewOrientation,
                                                                    DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null);
            //59.4 x 42.0   29.7 X 21.0
            DrawingView oTopView = oSheet.DrawingViews.AddProjectedView(oBaseView,
                                                                        oTG.CreatePoint2d(28.7, 29),
                                                                        DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null);

            //Projected views
            DrawingView oRightView = oSheet.DrawingViews.AddProjectedView(oBaseView,
                                                                          oTG.CreatePoint2d(45, 21),
                                                                          DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null);

            //look through the curves in view finds top horiz curve. Find an edge
            oSheet.RevisionTables.Add(oTG.CreatePoint2d(48.4, 23.5));      //1mm div 10//1 row = 4

            DrawingCurve oSelectedCurve = null;

            foreach (DrawingCurve oCurve in oBaseView.get_DrawingCurves(null))
            {
                //Skip Circles
                if (oCurve.StartPoint != null && oCurve.EndPoint != null)
                {
                    if (WithinTol(oCurve.StartPoint.Y, oCurve.EndPoint.Y, 0.001))
                    {
                        if (oSelectedCurve == null)
                        {
                            //This is the first horizontal curve found.
                            oSelectedCurve = oCurve;
                        }
                        else
                        {
                            //Check to see if this curve is higher (smaller x value) than the current selected
                            if (oCurve.MidPoint.Y < oSelectedCurve.MidPoint.X)
                            {
                                oSelectedCurve = oCurve;
                            }
                        }
                    }
                }
            }
            //Create geometry intents point for the curve.
            GeometryIntent oGeomIntent1 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent);
            GeometryIntent oGeomIntent2 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent);
            Point2d        oDimPos      = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y);

            //set up Dim
            GeneralDimensions oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions;

            //Styles sty = oDoc.StylesManager.Styles   ;
            // DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles["Drax Dim Above"];
            //MessageBox.Show(cmbDimStyles.Text);
            DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles[cmbDimStyles.Text];

            //Set Layer
            //Layer layer = oDoc.StylesManager.Layers["D"];
            //MessageBox.Show(cmbLayers.Text);
            Layer layer = oDoc.StylesManager.Layers[cmbLayers.Text];

            //Create the dimension.
            LinearGeneralDimension oLinearDim;

            oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2,
                                                      DimensionTypeEnum.kAlignedDimensionType, true,
                                                      dimstyle,
                                                      layer);


            string newfilename;
            string swapfilename;

            newfilename  = "";
            swapfilename = "";
            //Build New Filname
            Inventor.PropertySet InvPropertySet = oBlockPart.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"];
            swapfilename = oBlockPart.FullFileName.Substring(0, oBlockPart.FullFileName.LastIndexOf("\\") + 1);
            //MessageBox.Show(swapfilename);
            newfilename = swapfilename + InvPropertySet["FULLFILENAME"].Value + ".idw";
            oBlockPart.Close(true);
            oDoc.SaveAs(newfilename, true);
            oDoc.Close(true);
        }