|
export bom with drawings
please help, i'm using a macro to export a bom from a drawing. i search the vault for the part number using getspecificdocument then look to see where used and get drawing linked to part. all works fine until the part i'm looking for doesn't exist in the vault. i then get an exception when i try to get the whereused list. i would like to know if the getspecificdocument fails to find the part.
does anyone how to check if getspecificdocument doesn't return a result ?
check the variable that you set. i.e.:
dim doc as ???
set doc = ???.getspecificdocument(whatever)
then do this check:
if doc is nothing then
' failed to get
else
' ok
end if
sorry i taken so long to reply.
thanks for the reply.
i get an error invalid use of property at compile.
i have:
dim connection as pdmworks.pdmwconnection
dim doc as pdmworks.pdmwdocument
also tried it without the pdmworks.
the code works ok when documents are found. funny thing is
set doc = nothing compiles ok
i have the macro running by using on error resume next but i would like a better way of handling it.
thanks
paste the entire code and highlight the line where the compiler states the error is
no shame in using "on error resume next" to handle the situation. perfectly legit. you could use "on error goto [line name]" as well. that would allow you to handle different types of errors.
you can use "on error goto 0" to turn off error handling.
thats fine if the error is meant to be occuring... but in this case it sounds more like erronous code
here's the entire code probably more than you need.
sub exporttable(swtable as sldworks.tableannotation)
dim connection as pdmworks.pdmwconnection
dim adoc as pdmworks.pdmwdocument
dim partlinks as pdmworks.pdmwlinks
dim partlink as pdmworks.pdmwlink
dim strdrawing, strtemp, strdrawingprev as string
set connection = createobject("pdmworks.pdmwconnection") 'create connection
connection.login "api", "1234", "hobbssbs" ' connect to vault
dim swann as sldworks.annotation
dim nnumcol as long
dim nnumrow as long
dim srowstr as string
dim i as long
dim j as long
dim k as long
dim strsonum as string
dim strsolinenum as string
dim strbomtitle as string
dim spathname as string
dim res as string
dim objexcelobject as excel.application
dim objbook1 as excel.workbook
dim objsheet1 as excel.worksheet
set objexcelobject = createobject("excel.application")
objexcelobject.visible = false
objexcelobject.screenupdating = false
objexcelobject.interactive = false
set objbook1 = objexcelobject.workbooks.add()
set objsheet1 = objbook1.activesheet
set swann = swtable.getannotation
strsonum = inputbox("enter sales order number", "create bom", "[enter so number]")
strsolinenum = inputbox("enter line number", "create bom", "[enter so line number]")
strbomtitle = "sales order " & strsonum & " line number " & strsolinenum ' bom heading
'strsonum = "so-" & strsonum & "-" & strsolinenum 'filename
strsonum = strsonum & "-" & strsolinenum 'filename
objbook1.saveas "\\hobbssbs\company\engineering\engineeringbom\" & strsonum
objsheet1.activate
'set worksheet name
objsheet1.name = strsonum & " eng bom"
nnumcol = swtable.columncount
k = nnumcol + 99
nnumrow = swtable.rowcount
' only export bills of materials (edit, or remove to process all tables)
if swtable.type <> swconst.swtableannotationtype_e.swtableannotation_billofmaterials then exit sub
' get the table contents
for i = 0 to nnumrow - 1
for j = 0 to nnumcol
if swtable.displayedtext(i, j) = "part number" then k = j ' set part number column
if j = k and i <> 0 then 'if part number column and not first row
objsheet1.range("a3").offset(i, j).value = swtable.displayedtext(i, j) 'puts part num in part column
strtemp = swtable.displayedtext(i, j) & ".sldprt"
set adoc = connection.getspecificdocument(strtemp)
on error resume next 'should check if getspecificdocument returns a result
set partlinks = adoc.whereused 'get an error here at runtime if adoc is not found
for each partlink in partlinks
if lcase(right(partlink.name, 6)) = "slddrw" then
strtemp = left(partlink.name, len(partlink.name) - 7)
strtemp = ucase(strtemp)
strdrawing = strtemp & " rev " & partlink.revision
if strdrawing = strdrawingprev then strdrawing = "" 'check a new doc was found and not an error
objsheet1.range("a3").offset(i, (j + 1)).value = strdrawing ' write drawing num in next column
strdrawingprev = strdrawing
end if
next partlink
end if
if j = k and i = 0 then 'headings
objsheet1.range("a3").offset(i, j).value = swtable.displayedtext(i, j)
objsheet1.range("a3").offset(i, (j + 1)).value = "drawing"
objsheet1.range("a3").offset(i, j).font.bold = true ' bold top column
objsheet1.range("a3").offset(i, (j + 1)).font.bold = true ' bold top column
end if
if j > k then ' after part column
objsheet1.range("a3").offset(i, (j + 1)).value = swtable.displayedtext(i, j)
if i = 0 then objsheet1.range("a3").offset(i, (j + 1)).font.bold = true ' bold top column
end if
if j < k then 'before part column
objsheet1.range("a3").offset(i, j).value = swtable.displayedtext(i, j)
if i = 0 then objsheet1.range("a3").offset(i, j).font.bold = true ' bold top column
end if
z:
next j
next i
objsheet1.range("a1").activate
objsheet1.range("a1", objsheet1.range("a1").specialcells(xlcelltypelastcell)).columns.autofit
objsheet1.range("a1").offset(0, 1).value = strbomtitle
objsheet1.range("a1").offset(0, 1).font.bold = true
i = i + 3
objsheet1.range("a1").offset(i, 0).value = "created " & date
' clean-up
objexcelobject.screenupdating = true
objexcelobject.interactive = true
objexcelobject.activeworkbook.save
objexcelobject.workbooks.close
objexcelobject.quit
set objsheet1 = nothing
set objbook1 = nothing
set objexcelobject = nothing
connection.logout
end sub
the highlighted part is where the error occurs now i try to get the whereused of a doc thats empty. if i try if adoc = nothing then it throws up an error when compiling that line with invalid use of property.
thanks for your thoughts.
you didn't implement what i posted in the previous post. change:
....
set adoc = connection.getspecificdocument(strtemp)
on error resume next 'should check if getspecificdocument returns a result
set partlinks = adoc.whereused 'get an error here at runtime if adoc is not found
for each partlink in partlinks
...
to:
set adoc = connection.getspecificdocument(strtemp)
if adoc is nothing then
msgbox "error gettings document"
exit sub
end if
set partlinks = adoc.whereused 'get an error here at runtime if adoc is not found
for each partlink in partlinks
...
answer i did try what you suggested or at least i thought i did.
i tried if adoc = nothing instead of is nothing
it's working great now.
thanks for your help.
quick |
|