几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 10:39 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】editing blocks per drawing shee

editing blocks per drawing sheet?
i have a question. i have several drawing document sheets that have the same block instance on them. what i have is a macro that will update/replace them but it doesn't do it for just that sheet, it does it for all and if replacing them puts them all on the active sheet you run the macro against. the question, is how do you get the macro to focus and change only the blocks on that sheet and leave the rest unchanged on the following sheets? i've played with the focuslocked without luck. maybe i'm not understanding how it works or need to try something different. i've also tried looping through the features in the document, looking at the drawing sheets only method with no luck either. so any pointers or samples would be much appreciated.
here is the array of info i'm gathering from the blocks to use for replacement, but it gathers it from all sheets:
-----see message below-----
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
edited: 09/11/2008 at 05:17 pm by william crosby
ok, here's what i have for a working copy to detect with, but still have the issue of it picking up all block instances regardless of what sheet the routine runs on. only want the block instances for that sheet. change the const blkitem1 = "block1" to whatever block name you create.
'----------code---------------
option explicit
dim swapp as sldworks.sldworks ' solidworks application
dim swmodel as sldworks.modeldoc2 ' layout object access
dim swdraw as sldworks.drawingdoc ' drawing layout object access
dim swsketchmgr as sldworks.sketchmanager ' sketch manager object access
dim swselmgr as sldworks.selectionmgr ' selection manager object access
dim swblockinst as sldworks.sketchblockinstance ' delcare block instance
dim swblockdef as sldworks.sketchblockdefinition ' declare block definition
dim swfeat as sldworks.feature ' declare feature objects
dim swsheet as sldworks.sheet ' sheet object access
dim swview as sldworks.view ' view object access
const blkitem1 = "block1" ' define name of block
dim vblockdefs as variant, vblockinsts as variant
dim vblockdefcount as long, vblockinstcount as long
dim blocksipnt() as variant ' capture block insertion point
dim blocksrot() as variant ' capture block rotation
dim blocksscl() as variant ' capture block scale
dim blkexist as boolean ' declare true or false for block operations
sub checkforblock()
on error resume next
set swapp = application.sldworks
set swmodel = swapp.activedoc
set swsketchmgr = swmodel.sketchmanager
set swselmgr = swmodel.selectionmanager
blkexist = false
set swdraw = swmodel
set swview = swdraw.getfirstview
do while not swview is nothing
debug.print "sheet name = " & swview.name
vblockdefs = swsketchmgr.getsketchblockdefinitions ' get block definitions
debug.print "block definition count = " & swsketchmgr.getsketchblockdefinitioncount
if not isempty(vblockdefs) then ' else traverse block definitions
for vblockdefcount = lbound(vblockdefs) to ubound(vblockdefs) ' loop block definition references
set swblockdef = vblockdefs(vblockdefcount)
set swfeat = swblockdef.getfeature
if swfeat.name = blkitem1 then ' verify block name
debug.print "block definition name = " & swfeat.name
vblockinsts = swblockdef.getinstances
if false = isempty(vblockinsts) then ' traverse block instances
for vblockinstcount = lbound(vblockinsts) to ubound(vblockinsts) ' loop block instance references
debug.print "block instance count = " & swblockdef.getinstancecount
set swblockinst = vblockinsts(vblockinstcount)
blkexist = swblockinst.select(false, nothing)
set swblockinst = swselmgr.getselectedobject6(1, -1)
debug.print "block instance name = " & swblockinst.name
'assign block insert point, scale & rotation elements to array
redim preserve blocksipnt(vblockinstcount) as variant
set blocksipnt(vblockinstcount) = swblockinst.instanceposition
blocksipnt(vblockinstcount) = blocksipnt(vblockinstcount).arraydata ' block insertion point
redim preserve blocksrot(vblockinstcount) as variant
blocksrot(vblockinstcount) = swblockinst.angle ' block angle
redim preserve blocksscl(vblockinstcount) as variant
blocksscl(vblockinstcount) = swblockinst.scale2 ' block scale
swmodel.clearselection2 true ' clear selection
next vblockinstcount
end if
end if
next vblockdefcount
end if
set swview = swview.getnextview
loop
if blkexist = false then ' block still doesn't exist notify user
msgbox "warning! there are no block instances in this document tab", vbexclamation, "no block instance found"
elseif blkexist = true then ' if block exist then do something to it
msgbox "got those values you wanted, now what?"
end if
end sub
'-------
did some code refinement ^
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
edited: 09/11/2008 at 06:00 pm by william crosby
answer finally got it. this is it and works flawlessly. if you want to use it you need to declare your objects and vars but you get the logic.
'-------the code-------------
private sub checkforblock()
on error resume next
set swapp = application.sldworks
set swmodel = swapp.activedoc
set swsketchmgr = swmodel.sketchmanager
set swselmgr = swmodel.selectionmanager
set swdraw = swmodel
blkexist = false
' clear selections
blockval = swselmgr.deselect2(1, -1)
swmodel.clearselection2 true
vblockdefs = swsketchmgr.getsketchblockdefinitions ' get block definitions
if not isempty(vblockdefs) then ' traverse block definitions
for blockdefcount = lbound(vblockdefs) to ubound(vblockdefs) ' loop block definitions
set swblockdef = vblockdefs(blockdefcount)
set swfeat = swblockdef.getfeature
if swfeat.name = blkitem1 then ' verify block name
set swsheet = swdraw.getcurrentsheet
viewnames = swsheet.getviews
set swview = swdraw.getfirstview
set swsketch = swview.getsketch
vblockinsts = swsketch.getsketchblockinstances
if false = isempty(vblockinsts) then ' traverse block instances
for blockinstcount = lbound(vblockinsts) to ubound(vblockinsts) ' loop block instances
set swblockinst = vblockinsts(blockinstcount)
if swblockinst.name like blkitem1 & "*" then ' check the block instance name
blockval = swblockinst.select(true, nothing)
blkexist = true
set swblockinst = swselmgr.getselectedobject6(1, -1)
'assign block insert point, scale & rotation elements to array
redim preserve blocksipnt(blockinstcount) as variant
set blocksipnt(blockinstcount) = swblockinst.instanceposition
blocksipnt(blockinstcount) = blocksipnt(blockinstcount).arraydata ' block insertion point
redim preserve blocksrot(blockinstcount) as variant
blocksrot(blockinstcount) = swblockinst.angle ' block angle
redim preserve blocksscl(blockinstcount) as variant
blocksscl(blockinstcount) = swblockinst.scale2 ' block scale
swmodel.clearselection2 true ' clear selection
end if
next blockinstcount
end if
end if
next blockdefcount
end if
if blkexist = false then ' block still doesn't exist notify user
msgbox "warning! there are no block instances in this document tab", vbexclamation, "no block instance found"
elseif blkexist = true then ' if block exist then do something to it
msgbox "got those values you wanted, now what?"
end if
end sub
'----------
added one more step to verify the instance
on the face of the drawing document not just the
feature tree
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
edited: 09/16/2008 at 03:08 pm by william crosby
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】can you modelize a drawing view yang686526 SolidWorks二次开发 0 2009-04-13 09:31 AM
【转帖】arget sheet drawing from excel yang686526 SolidWorks二次开发 0 2009-04-12 10:37 PM
【转帖】see what partassembly a drawing points to yang686526 SolidWorks二次开发 0 2009-04-12 10:19 PM
【转帖】how to save to dxf in active drawing file location yang686526 SolidWorks二次开发 0 2009-04-12 09:23 PM
【转帖】how to save to dxf in active drawing file location yang686526 SolidWorks二次开发 0 2009-04-12 06:38 PM


所有的时间均为北京时间。 现在的时间是 08:16 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多