Zobrazit plnou verzi příspěvku: Automatické přejmenování těles

madep
02.01.2022, 14:25
Ahoj všem,Rád používám víceobjemová tělesa jako řídící modely pro sestavy. Abych si ušetřil práci s pojmenováváním souborů při exportu do sestavy, nejdříve si všechna tělesa očísluju. Ruční přepisování je trochu nepohodlné. Podařilo se mi najít výborné pravidlo. Takže všem, kdo takto pracujete je k dispozici níže.Martin DeptaEltodo a.s.'------- start of ilogic ------'check for custom iProperty and add it if not foundDim prefix As String = "Prefix"customPropertySet = ThisDoc.Document.PropertySets.Item _("Inventor User Defined Properties")Try        prop= customPropertySet.Item(prefix)Catch      ' Assume error means not found            customPropertySet.Add("", prefix)End Try'write the part number to the Prefix iProperty if it is emptyIf iProperties.Value("Custom", "Prefix") = "" TheniProperties.Value("Custom", "Prefix") = iProperties.Value("Project", "Part Number") & "_"ElseEnd If'check that this active document is a part file   Dim partDoc As PartDocumentIf ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject ThenMessageBox.Show ("Please open a part document", "iLogic")End If'define the active documentpartDoc = ThisApplication.ActiveDocumentDim solid As SurfaceBodyDim i As Integer'get input from userprefix = InputBox("Enter a prefix for the solid body names", "iLogic", iProperties.Value("Custom", "Prefix"))'write input back to custom iPropertyiProperties.Value("Custom", "Prefix") = prefixi = 1'rename all solid bodies incrementing suffixFor Each solid In partDoc.ComponentDefinition.SurfaceBodiessolid.Name = prefix + IIf(i < 10, "0" + CStr(i), CStr(i))i = i + 1Next'------- End Of ilogic ------

Boleslav
02.01.2022, 15:20
Dík, to by mohlo být užitečné.

Navara
02.01.2022, 15:49
Moc hezký Tady jsem jenom udělal pár kosmetických změnPřesunul jsem kontrolu typu dokumentu na začátekOdstranil jsem vícenásobné získávání aktivního dokumentuSjednotil jsem použití iVlastnosti pro prefix do jedné proměnnéRozdělil jsem použití proměnné prefix pro název iVlastnosti a její hodnotuZjednodušil jsem formátování finálního názvu tělesa[code]'------- start of ilogic ------'check that this active document is a part file   Dim partDoc As PartDocumentIf ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then    MessageBox.Show("Please open a part document", "iLogic")    ReturnEnd If'define the active documentpartDoc = ThisApplication.ActiveDocument'check for custom iProperty and add it if not foundDim prefixPropertyName As String = "Prefix"Dim customPropertySet = partDoc.PropertySets.Item("Inventor User Defined Properties")Dim prefixProperty As Inventor.PropertyTry    prefixProperty = customPropertySet.Item(prefixPropertyName)Catch    ' Assume error means not found    prefixProperty = customPropertySet.Add("", prefixPropertyName)End Try'write the part number to the Prefix iProperty if it is emptyIf String.IsNullOrEmpty(prefixProperty.Value.ToString()) Then    prefixProperty.Value = iProperties.Value("Project", "Part Number") & "_"End If'get input from userDim bodyPrefix = InputBox("Enter a prefix for the solid body names", "iLogic", prefixProperty.Value.ToString())'write input back to custom iPropertyprefixProperty.Value = bodyPrefix'rename all solid bodies incrementing suffixDim i As Integer = 1For Each solid As SurfaceBody In partDoc.ComponentDefinition.SurfaceBodies    solid.Name = String.Format("{0}{1:00}", bodyPrefix, i)    i += 1Next'------- End Of ilogic ------[/code]