private void GetTesselationData(IComponent2 comp, out float[] tessTriangs, out float[] tessNorms) { IModelDoc2 compModel = comp.IGetModelDoc(); if (compModel == null) { if (Path.GetExtension(comp.GetPathName()).Equals(".sldprt", StringComparison.CurrentCultureIgnoreCase)) { tessTriangs = comp.GetTessTriangles(true) as float[]; tessNorms = comp.GetTessNorms() as float[]; } else { throw new NotSupportedException("Only parts are supported"); } } else { if (compModel is IPartDoc) { GetTesselationDataFromPart(compModel as IPartDoc, out tessTriangs, out tessNorms); } else { throw new NotSupportedException("Only parts are supported"); } } }
public void Main() { try { IModelDoc2 model = swApp.IActiveDoc2; if (model != null) { string fileNameBase = ""; float[] tessTriangs; float[] tessNorms; if (model is IPartDoc) { fileNameBase = model.GetTitle(); GetTesselationDataFromPart(model as IPartDoc, out tessTriangs, out tessNorms); } else if (model is IAssemblyDoc) { IComponent2 comp = model.ISelectionManager.GetSelectedObjectsComponent3(1, -1) as IComponent2; if (comp != null) { GetTesselationData(comp, out tessTriangs, out tessNorms); fileNameBase = comp.GetPathName(); } else { throw new NullReferenceException("Please select component"); } } else { throw new NotSupportedException("Document type is not support, parts or assembly components are supported"); } string filePath = BrowseFile(Path.GetFileNameWithoutExtension(fileNameBase)); if (!string.IsNullOrEmpty(filePath)) { ExportToStl(filePath, tessTriangs, tessNorms, m_Transform); } } else { throw new NullReferenceException("Please open part or assembly"); } } catch (Exception ex) { swApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk); } }
/// <summary> /// 获取组件的类型 /// </summary> /// <param name="comp"></param> /// <returns></returns> public static swDocumentTypes_e GetCompType(this IComponent2 comp) { string extension = Path.GetExtension(comp.GetPathName()); switch (extension.ToLower()) { case ".sldprt": return(swDocumentTypes_e.swDocPART); case ".sldasm": return(swDocumentTypes_e.swDocASSEMBLY); default: throw new FileFormatException(string.Format("can not get :{0} 's type,The component's filepath is {1}", comp.Name2, comp.GetPathName())); } }
public void GetParts(IComponent2 Comp) { try { if (Settings.Run) { bool Include = true; Object Children; //TreferencedDoc ActDoc = new TreferencedDoc(); if (!Comp.IsSuppressed())//Wenn Zeichnung nicht unterdrückt { Part part = new Part(); modeldoc = (ModelDoc2)Comp.GetModelDoc2(); if (modeldoc != null) { string FileName = Path.GetFileNameWithoutExtension(modeldoc.GetPathName()); part.Name = FileName.Substring(FileName.LastIndexOf("/") + 1); foreach (Part partfromList in Parts) { if (SWX.Settings.NotInBil && Comp.ExcludeFromBOM) { Include = false; break; } if (Settings.OnlyAssembly && modeldoc.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY) { Include = false; break; } if (partfromList.Name == part.Name) { partfromList.Cnt++; Include = false; break; } } if (Include) { part.PathName = modeldoc.GetPathName(); part.RefConfig = Comp.ReferencedConfiguration; part.Released = modeldoc.GetCustomInfoValue("", "Status"); part.Beschreibung = modeldoc.GetCustomInfoValue("", "Description"); part.IsFastener = modeldoc.GetCustomInfoValue("", "isfastener"); if (modeldoc.GetCustomInfoValue("", "Medienberührend").ToUpper() == "JA") { part.Zertifikat = true; } part.Revision = modeldoc.GetCustomInfoValue(part.RefConfig, "Revision"); modelDocExtension = modeldoc.Extension; //int ret = modelDocExtension.ToolboxPartType; //if (ret != 0) //{ // part.IsToolBoxPart = true; //} } } else { part.PathName = modeldoc.GetPathName(); string TempName = Path.GetFileNameWithoutExtension(Comp.GetPathName()); part.Name = TempName.Substring(TempName.LastIndexOf("/") + 1); //KKS.KKS_Message.Show(ActDoc.Name); part.RefConfig = ""; part.Released = modeldoc.GetCustomInfoValue("", "Status"); part.Revision = modeldoc.GetCustomInfoValue(part.RefConfig, "Revision"); } if (Include) { Parts.Add(part); } } Children = Comp.GetChildren(); foreach (Object com in (Object[])Children) { Child = (IComponent2)com; GetParts(Child); } } } catch (Exception ex) { if (KKS.KKS_Message.Show("Folgender Fehler ist aufgetreten. Um den Vorgang weiter zu führen Klicke auf OK. /n" + ex.Message, "Fehler", true, "OK", "Abbrechen") == System.Windows.Forms.DialogResult.Cancel) { Settings.Run = false; } } }