Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Run Macro in Assembly to remove the properties to all components

Status
Not open for further replies.

Rogeli031

Automotive
Apr 17, 2014
1
0
0
US
i have the below Macro in order to open each parts of the active assembly, what i need is after they open, delete all the Properties (also the custom) except the Description
They just open all the parts of the assembly or delete the properties, but don't works at the same time for all the parts, some body can give me a tips to fixed?

Thanks



Dim swDoc As SldWorks.ModelDoc2
Dim swAllDocs As EnumDocuments2
Dim FirstDoc As SldWorks.ModelDoc2
Dim dummy As Boolean
Dim NumDocsReturned As Long
Dim DocCount As Long
Dim i As Long
Dim sMsg As String
Dim swApp As SldWorks.SldWorks
Dim bDocWasVisible As Boolean
Dim OpenWarnings As Long
Dim OpenErrors As Long
Dim DwgPath As String
Dim myDwgDoc As SldWorks.ModelDoc2

Sub ShowAllOpenFiles()

Set swApp = Application.SldWorks
Set swAllDocs = swApp.EnumDocuments2
Set FirstDoc = swApp.ActiveDoc
DocCount = 0
swAllDocs.Reset
swAllDocs.Next 1, swDoc, NumDocsReturned
While NumDocsReturned <> 0
bDocWasVisible = swDoc.Visible
swApp.ActivateDoc swDoc.GetPathName
DwgPath = swDoc.GetPathName
If (LCase(Right(DwgPath, 3)) <> "drw") And (DwgPath <> "") Then
DwgPath = Left(DwgPath, Len(DwgPath) - 3) & "drw"
Set myDwgDoc = swApp.OpenDoc6(DwgPath, swDocDRAWING, swOpenDocOptions_Silent, "", OpenErrors, OpenWarnings)
If Not myDwgDoc Is Nothing Then swApp.ActivateDoc myDwgDoc.GetPathName
Set myDwgDoc = Nothing
End If
'End If
swAllDocs.Next 1, swDoc, NumDocsReturned
DocCount = DocCount + 1
Wend
swApp.ActivateDoc FirstDoc.GetPathName

End Sub

Sub main()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim retval As String

Dim Desc As String

Dim retvals As String

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Desc = swModel.GetCustomInfoCount

retval = swModel.DeleteCustomInfo("Number")

retval = swModel.DeleteCustomInfo("DrawnBy")

retval = swModel.DeleteCustomInfo("CheckedBy")

retval = swModel.DeleteCustomInfo("Engineered By")

retval = swModel.DeleteCustomInfo("EngAppDate")

retval = swModel.DeleteCustomInfo("Project#")

retval = swModel.DeleteCustomInfo("DrawnDate")

retval = swModel.DeleteCustomInfo("CheckedDate")

retval = swModel.DeleteCustomInfo("Out source Co.")
retval = swModel.DeleteCustomInfo("OutSourceDate")
retval = swModel.DeleteCustomInfo("Number")
retval = swModel.DeleteCustomInfo("Revision")
retval = swModel.DeleteCustomInfo("Designer")
retval = swModel.DeleteCustomInfo("Detailer")
retval = swModel.DeleteCustomInfo("DesignDate")
retval = swModel.DeleteCustomInfo("Released Date")
retval = swModel.DeleteCustomInfo("State")
retval = swModel.DeleteCustomInfo("Purchased")
retval = swModel.DeleteCustomInfo("TABULATION BALLOON")
retval = swModel.DeleteCustomInfo("SWFormatSize")
retval = swModel.DeleteCustomInfo("Machine")
retval = swModel.DeleteCustomInfo("Designer By")
retval = swModel.DeleteCustomInfo("Weight")
retval = swModel.DeleteCustomInfo("OriginationDate")
retval = swModel.DeleteCustomInfo("Component Type")
retval = swModel.DeleteCustomInfo("Manufacturer")
retval = swModel.DeleteCustomInfo("Manufacturer Number")
retval = swModel.AddCustomInfo3("", "Description", swCustomInfoText, Desc)

'retval = swModel.DeleteConfiguration("Desc")

'retval = swModel.AddCustomInfo3("", "Number", swCustomInfoText, "T50000")

'retval = swModel.DeleteCustomInfo("COMPANY")

'retval = swModel.AddCustomInfo3("", "COMPANY", swCustomInfoText, "VENTURADS.COM")


End Sub




 
Replies continue below

Recommended for you

Hi!!

SolidWorks macro always start with Main procedure. You have written Main procedure to delete custom properties alone. The 'ShowAllOpenFiles' procedure only opens all the part files and drawing files. You have to change 'ShowAllOpenFiles' as Main and main as another one. Another problem is that You are no where calling second sub procedure in your coding.

I have altered your code slightly. Just check it.

-----------
Dim swDoc As SldWorks.ModelDoc2
Dim swAllDocs As EnumDocuments2
Dim FirstDoc As SldWorks.ModelDoc2
Dim dummy As Boolean
Dim NumDocsReturned As Long
Dim DocCount As Long
Dim i As Long
Dim sMsg As String
Dim swApp As SldWorks.SldWorks
Dim bDocWasVisible As Boolean
Dim OpenWarnings As Long
Dim OpenErrors As Long
Dim DwgPath As String
Dim myDwgDoc As SldWorks.ModelDoc2

Sub main() 'ShowAllOpenFiles()

Set swApp = Application.SldWorks
Set swAllDocs = swApp.EnumDocuments2
Set FirstDoc = swApp.ActiveDoc
DocCount = 0
swAllDocs.Reset
swAllDocs.Next 1, swDoc, NumDocsReturned
While NumDocsReturned <> 0
bDocWasVisible = swDoc.Visible
swApp.ActivateDoc swDoc.GetPathName
DwgPath = swDoc.GetPathName
DeleteProperties
If (LCase(Right(DwgPath, 3)) <> "drw") And (DwgPath <> "") Then
DwgPath = Left(DwgPath, Len(DwgPath) - 3) & "drw"
Set myDwgDoc = swApp.OpenDoc6(DwgPath, swDocDRAWING, swOpenDocOptions_Silent, "", OpenErrors, OpenWarnings)
If Not myDwgDoc Is Nothing Then swApp.ActivateDoc myDwgDoc.GetPathName
Set myDwgDoc = Nothing
End If
'End If
swAllDocs.Next 1, swDoc, NumDocsReturned
DocCount = DocCount + 1
Wend
swApp.ActivateDoc FirstDoc.GetPathName

End Sub

Sub DeleteProperties()

'Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim retval As String

Dim Desc As String

Dim retvals As String

'Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Desc = swModel.GetCustomInfoCount

retval = swModel.DeleteCustomInfo("Number")

retval = swModel.DeleteCustomInfo("DrawnBy")

retval = swModel.DeleteCustomInfo("CheckedBy")

retval = swModel.DeleteCustomInfo("Engineered By")

retval = swModel.DeleteCustomInfo("EngAppDate")

retval = swModel.DeleteCustomInfo("Project#")

retval = swModel.DeleteCustomInfo("DrawnDate")

retval = swModel.DeleteCustomInfo("CheckedDate")

retval = swModel.DeleteCustomInfo("Out source Co.")
retval = swModel.DeleteCustomInfo("OutSourceDate")
retval = swModel.DeleteCustomInfo("Number")
retval = swModel.DeleteCustomInfo("Revision")
retval = swModel.DeleteCustomInfo("Designer")
retval = swModel.DeleteCustomInfo("Detailer")
retval = swModel.DeleteCustomInfo("DesignDate")
retval = swModel.DeleteCustomInfo("Released Date")
retval = swModel.DeleteCustomInfo("State")
retval = swModel.DeleteCustomInfo("Purchased")
retval = swModel.DeleteCustomInfo("TABULATION BALLOON")
retval = swModel.DeleteCustomInfo("SWFormatSize")
retval = swModel.DeleteCustomInfo("Machine")
retval = swModel.DeleteCustomInfo("Designer By")
retval = swModel.DeleteCustomInfo("Weight")
retval = swModel.DeleteCustomInfo("OriginationDate")
retval = swModel.DeleteCustomInfo("Component Type")
retval = swModel.DeleteCustomInfo("Manufacturer")
retval = swModel.DeleteCustomInfo("Manufacturer Number")
retval = swModel.AddCustomInfo3("", "Description", swCustomInfoText, Desc)

'retval = swModel.DeleteConfiguration("Desc")

'retval = swModel.AddCustomInfo3("", "Number", swCustomInfoText, "T50000")

'retval = swModel.DeleteCustomInfo("COMPANY")

'retval = swModel.AddCustomInfo3("", "COMPANY", swCustomInfoText, "VENTURADS.COM")


End Sub
---------------------------------

Regards
V K Amirtharaj
EGS Computers India Pvt Ltd
Dassault System SolidWorks Reseller
Chennai | Tamilnadu | India
 
Status
Not open for further replies.
Back
Top