几何尺寸与公差论坛

 找回密码
 注册
查看: 965|回复: 0

【转帖】unable to select bom

[复制链接]
发表于 2009-4-13 15:06:12 | 显示全部楼层 |阅读模式
unable to select bom
hi there,
i am an ms office vba developer who has been tasked to write a custom application that will upload a bom table in solidworks to our mrp system.
i have been attempting to use the exportbom macro i found at
hi chris
here is a sample program that should get your bom. in this sample if you have a drawing with a bom open the first part of the program will search for the bom and get it for you. underneath the asterisks it will get the column title of the colnum and then delete that column so you will want to comment that line out. it will not delete the quantity column which i am trying to hide but can not find the code.
dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
dim drawing as sldworks.drawingdoc
dim view as sldworks.view
dim bret as boolean
dim t as string ' temporary text
dim colnum as integer
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set drawing = part
set sheet = drawing.getcurrentsheet
set view = drawing.getfirstview
dim bomtableann as sldworks.bomtableannotation
dim tableannotation as sldworks.tableannotation
'findbom
'get the first view from the drawingdoc
set view = drawing.getfirstview 'this is the sheet
'traverse all the tableannotations for the view looking for bom table type
set tableannotation = view.getfirsttableannotation
do while not tableannotation is nothing
dim tabletype as long
tabletype = tableannotation.type
if tabletype = 2 then ' bill of materials
set bomtableann = tableannotation
exit do
end if
set tableannotation = tableannotation.getnext
loop
'work with bom **********************************************************
colnum = 2 ' enter number of column to delete here
t = tableannotation.getcolumntitle(colnum) 'gets name of column
bret = tableannotation.deletecolumn(colnum) ' deletes column here
if bret = false then ' checks to see if column was delete or not
debug.print "column " & t & " was not deleted"
else
debug.print "column " & t & " deleted"
end if
end sub
i hope this helps.
dan miel
chris,
just remove this line in the macro to process all tables:
' only export bills of materials (edit, or remove to process all tables)
if swtable.type <> swconst.swtableannotationtype_e.swtableannotation_billofmaterials then exit sub
a bom is a feature. iterate through features, and try to set a specific bom feature and see if it sticks.
function bomcount(indoc as object) as long
on error resume next
dim btdwg as sldworks.drawingdoc
dim btmod as sldworks.modeldoc2
dim btfeat as sldworks.feature
dim btbomfeat as sldworks.bomfeature
bomcount = 0
set btdwg = indoc
if btdwg is nothing then goto bctexit
set btmod = btdwg
set btfeat = btmod.firstfeature
do while not btfeat is nothing
set btbomfeat = btfeat.getspecificfeature2
if not btbomfeat is nothing then
bomcount = bomcount + 1
set btbomfeat = nothing
end if
set btfeat = btfeat.getnextfeature
loop
bctexit:
set btdwg = nothing 'sldworks.drawingdoc
set btmod = nothing 'sldworks.modeldoc2
set btfeat = nothing 'sldworks.feature
set btbomfeat = nothing 'sldworks.bomfeature
end function
his problem is the table is a general table not a bom so that wont work.
like i said just remove that line or change the enum to general table instead of bom, and your table will be picked up
hello all,
thanks for the replys. i am afraid i am still having the issue of the bom not being detected.
both code snippets depend on loops which test if a variable for the bom table has been assigned a value. in each case the bom table is not detected and assigned. therefore the code to read the bom is never activated.
i will address them in order.
dan,
i tried the code you posted. i encounter the same issue as my original post.
when the line
do while not tableannotation is nothing
is reached, the code does not detect my bom table and the loop is exited.
this is the line which assigns the variable:
set tableannotation = view.getfirsttableannotation
this doesn't seem to find my bom.
luke,
the line
if swtable.type <> swconst.swtableannotationtype_e.swtableannotation_billofmaterials then exit sub
is in the exporttable sub. this is never reached as it is called from main within the the following loop:
do while not swtable is nothing
' use built in function to manually export bom to text file, but will open fine as xls with warning
' that is is a text file. this function has a few drawbacks...
swtable.saveastext "c:\standard bom.xls", vbtab
' so create our own manual method instead
exporttable swtable
' get next table annotation for this view
set swtable = swtable.getnext
loop
this loop is immeadiately exited as the bom table is not assigned to the swtable variable.
the following line doesn't detect my bom:
set swtable = swview.getfirsttableannotation
i have tried a few things but nothing seems to be able to find my bom table. i don't know if this is significant but the bom is added from an excel template using the following menu option:
insert > table > excel bill of materials.
thanks for your help so far guys, any ideas about why the bom table is not detected?
thanks,
chris
that is the reason why; your table is not a sw table at all it is an activex excel object so you cannot do what you are after using this code it is totally different
hi luke,
thanks, that should mean that if i add a reference to the excel object model i can then manipulate it using excel functions.
i will try that out and let you know my results.
c
i'm getting nowhere fast i'm afraid to say.
i can't seem to find a way to detect the bom table in my solidworks document.
i now know it's a activex excel object but everything i try seems to look straight through it.
can anyone suggest how to detect it?
thanks,
chris
just select it using selectbyid2 passing in its name (default is workbook)
part.extension.selectbyid2("worksheet", "oleitem", 0, 0.2256290523729, 0, false, 0, nothing, 0)
hi luke,
thanks for your reply. i have tried the following:
part.extension.selectbyid2("worksheet", "oleitem", 0, 0.2256290523729, 0, false, 0, nothing, 0)
part.extension.selectbyid2("bill of materials1", "oleitem", 0, 0.2256290523729, 0, false, 0, nothing, 0)
part.extension.selectbyid2("worksheet", "bom", 0, 0.2256290523729, 0, false, 0, nothing, 0)
part.extension.selectbyid2("bill of materials1", "bom", 0, 0.2256290523729, 0, false, 0, nothing, 0)
all returned false. bill of materials1 is the object name according to the explorer bar on the left of the drawing.
i also tried this:
nolecnt = swsheet.getoleobjectcount
which returned zero. it seems that solidworks doesn't see my ole table.
any advice you can offer would be greatly appreciated, i'm rapidly approaching the hair-tearing out stage attempting to select this table object.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-22 12:59 , Processed in 0.036310 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表