Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I can open & replace drawing views using vba, but I also like to write the drawing number & file path of the drawing back to the part - already working in iLogic for individual drawings but the vba is for a batch of drawings.
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
'MessageBox.Show("docFName: " +docFName, "Debug")
' the file in the drawing is docFName, copy the PDM drawing number to it
iProperties.Value(docFName, "Custom", "PDM_Dwg_No") = DwgNo
'iProperties.Value(docFName,"Project", "Part Number")= DwgNo
fp = ThisDoc.Path
iProperties.Value(docFName, "Custom", "PDM_Dwg_No_Path") = fp
''
iProperties.Value(docFName, "Project", "Part Number") = DwgNo
iProperties.Value(docFName, "CUSTOM", "Number") = DwgNo
iProperties.Value(docFName, "CUSTOM", "ID") = DwgNo
This is the vba - the spreadsheet has filepaths to a list of drawings in column 1 & list of models in column 2.
The drawings are created with title blocks set up & project notes & a dummy part with 3 views & isometric.
Run the vba & the dummy part is swapped for a part on the list.
Need to add code to save & close, but need to write back to the part iproperties first.
Public Sub GetExcelData()
Dim excelApp As Excel.Application
' Try to connect to a running instance of Excel.
On Error Resume Next
Set excelApp = GetObject(, "Excel.Application")
'MsgBox "ac1"
If Err Then
Err.Clear
' Couldn't connect so start Excel. It's started invisibly.
Set excelApp = CreateObject("Excel.Application")
If Err Then
MsgBox "Cannot access excel."
Exit Sub
End If
End If
' You can make it visible if you want. This is especially
' helpful when debugging.
excelApp.Visible = True
' Open the spreadsheet.
Dim wb As Workbook
Set wb = excelApp.Workbooks.Open("C:\Users\a.canfield\Desktop\Batch Export\DrawingNumber.xlsx")
If Err Then
MsgBox "Unable to open the Excel document."
Exit Sub
End If
'MsgBox "ac2"
' Access a certain sheet.
Dim ws As WorkSheet
Set ws = wb.Worksheets.Item("Sheet1")
If Err Then
MsgBox "Unable to get the worksheet."
Exit Sub
End If
' Read some values from the sheet.
Dim row As Integer
Dim row2 As Integer
Dim col As Integer
row2 = Application.InputBox("Please enter number of rows in DrawingNumber.xlsx")
For row = 1 To row2
col = 2
'Debug.Print "Row: " & row & ", Col: " & col & " = " & ws.Cells(row, col)
DwgName = ws.Cells(row, 1)
PartName = ws.Cells(row, 2)
Set oDoc = ThisApplication.Documents.Open(DwgName)
oDoc.File.ReferencedFileDescriptors(1).ReplaceReference (PartName)
''
' Get the PropertySets object.
Dim oPropSets As PropertySets
Set oPropSets = oDoc.PropertySets
' Get the design tracking property set.
Dim oPropSet As PropertySet
Set oPropSet = oPropSets.Item("Design Tracking Properties")
' Get the part number iProperty.
Dim oPartNumiProp As Property
Set oPartNumiProp = oPropSet.Item("Part Number")
'Dim docFName As String
'docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
'MessageBox.Show("docFName: " +docFName, "Debug")
'MsgBox DwgName
MsgBox PartName
MsgBox oPartNumiProp.Value
' the file in the drawing is docFName, copy the PDM drawing number to it
' Dim oPrt As String
'
'oPrt = ThisApplication.Documents.ItemByName(PartName)
'
' ' Get the active document.
' 'Dim oDoc As Document
' 'Set oPrt = ThisApplication.ActiveDocument
'
' ' Get the PropertySets object.
' Dim oPropSetsPrt As PropertySets
' Set oPropSetsPrt = oDoc.PropertySets
'
' ' Get the design tracking property set.
' Dim oPropSetPrt As PropertySet
' Set oPropSetPrt = oPropSets.Item("Design Tracking Properties")
'
' ' Get the part number iProperty.
' Dim oPartNumiProp As Property
' Set oPartNumiProp = oPropSetPrt.Item("Part Number")
'
' ' Set the part number.
' oPartNumiProp.Value = "SamplePart001"
Next
End Sub
Regards
Andrew
Solved! Go to Solution.