/// <summary>
        /// Exports the .stl model for one link
        /// The model must already be switched to the correct configuration and all parts must be hidden before this method is called
        /// </summary>
        /// <param name="link">Link to be exported</param>
        /// <param name="configuration">The configuration that this link should be exported from</param>
        /// <param name="path">The path to save the .stl file</param>
        /// <param name="log">The logger to write messages to</param>
        public void ExportLink(Link link ,ModelConfiguration configuration, String path, ProgressLogger log)
        {
            log.WriteMessage("Exporting link " + link.Name + " as an STL. Configuration: " + ((ModelConfiguration.ModelConfigType)configuration.Type) + "; Path: " + path, false);

            int errors = 0;
            int warnings = 0;

            ModelDoc2 ActiveDoc = (ModelDoc2)asm;

            IsolateLink(link, configuration);

            int saveOptions = (int)swSaveAsOptions_e.swSaveAsOptions_Silent;

            ActiveDoc.Extension.SaveAs(path, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, saveOptions, null, ref errors, ref warnings);

            HideLink(link);

            log.WriteMessage("Correcting STL header");
            CorrectSTLMesh(path);
            log.WriteMessage("Finished exporting STL.");
        }
        /// <summary>
        /// Isolates the selceted link by hiding all other components
        /// </summary>
        /// <param name="l"> Link to be isolated</param>
        private void IsolateLink(Link l, ModelConfiguration config)
        {
            List<Component2> comps = new List<Component2>();
            foreach (modelComponent m in config.LinkComponents)
            {
                Component2 c = m.Component;
                if (c == null )
                    continue;

                if (((object[])c.GetChildren()).Length > 0)
                {
                    GetSubComponents(c, comps);
                }
                else
                {
                    comps.Add(c);
                    //System.Diagnostics.Debug.WriteLine(c.Name2);
                }
            }
            DispatchWrapper[] dispComps = Array.ConvertAll(comps.ToArray(),element=>new DispatchWrapper(element));

            SelectionMgr manager = ((ModelDoc2)asm).SelectionManager;
            SelectData data = manager.CreateSelectData();
            data.Mark = -1;
            manager.SuspendSelectionList();
            manager.AddSelectionListObjects(comps.ToArray(), data);

            ((ModelDoc2)asm).ShowComponent2();
            manager.ResumeSelectionList();
        }
Example #3
0
        /// <summary>
        /// Creates a new link belonging to the given assembly
        /// </summary>
        /// <param name="swApp">The Solidworks App</param>
        /// <param name="asm"> The assembly that this Link is in</param>
        /// <param name="swData"> The Storage model that this Link is stored in </param>
        /// <param name="path"> The path to the StorageModel location of this link </param>
        /// <param name="baseLink"> Whether this Link is the base link of the model or not </param>
        public Link(String path, int id)
        {
            this.Selected = false;
            this.asmDoc = RobotInfo.AssemDoc;
            this.modelDoc = RobotInfo.ModelDoc;
            this.swData = RobotInfo.SwData;
            this.path = path;
            this.swApp = RobotInfo.SwApp;
            this.Id = id;
            this.robot = RobotInfo.Robot;
            attachments = new List<Attachment>();
            ParentJoints = new List<Joint>();
            ChildJoints = new List<Joint>();
            nextAttachmentNum = 0;
            nextJointNum = 0;
            isBaseLink = false;

            if (swData.GetDouble(path) == 0)
            {
                swData.SetDouble(path, 1);
                Name = "NewLink";
                this.color = DefaultColors[0];
            }

            attachmentNums = new DoubleStorageArray(swData, path + "/attachmentNums");
            parentJointNums = new DoubleStorageArray(swData, path + "/jointNums");

            ModelConfiguration physical = new ModelConfiguration(path + "/physicalComps", (int)ModelConfiguration.ModelConfigType.Physical,this);
            ModelConfiguration visual = new ModelConfiguration(path + "/visualComps", (int)ModelConfiguration.ModelConfigType.Visual,this);
            ModelConfiguration collision = new ModelConfiguration(path + "/collisionComps", (int)ModelConfiguration.ModelConfigType.Collision,this);
            LinkModels = new ModelConfiguration[] {  physical, visual, collision };
        }