几何尺寸与公差论坛------致力于产品几何量公差标准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-12, 09:10 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how get an assembly name

how get an assembly name
i don´t know how to get an assembly name. i know that for components i have to write like this: name = swchildcomp.name2() but what about for assemblies?
thanks for your help!
edited: 02/18/2009 at 03:12 am by marian ruiz
hi marian,
you can use modeldoc2::gettitle
have a look in the api help there are several examples that display this.
cheers,,
--stav.
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
strip path and extension from modeldoc2: getpathname
gettitle was here in combination with solidpdm unreliable
thank you for your help!
i have done this macro to get the solidworks document's name:
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
set swapp = createobject("sldworks.application")
set swmodel = swapp.activedoc
dim nameas string
name = swmodel.gettitle()
name = left(name, instr(name, ".") - 1)
end sub
i think that it is the shortest!
slightly shorter:
sub main()
name = application.sldworks.activedoc.gettitle()
name = left(name, instr(name, ".") - 1)
end sub
note that this method (both your code above and this shorter version) is unreliable, though, and will not work in every case. it is permissible to have multiple "." in a filename. if your filename is "boltm6x1.0thread.sldprt" then this code will give you "boltm6x1".
also, gettitle follows your windows explorer setting for "hide extensions for known file types". if this option is checked in windows, gettitle will return the name with no extension and this code will fail.
i'll get you eh steve, if it's the last thing i dooooo!
edited: 02/18/2009 at 08:06 am by josh brady
josh highlighted a valid issue there.
a possible sollution can be splitting the title wherever there exists a "." character and checking the resulting strings and to be more precise the last string if it is the extension string.
essentially solidworks documents only use specific extesnions (for an assembly it will be .sldasm)
this can also be adjasted for any solidworks document by changing the extension string you are looking for.
so in code what i mean would be the following:
dim vresarray as variant
dim arraybound as integer
dim titlestr as string, asmtitle as string
.
.
.
titlestr = "a.title.with.several.dots.sldasm" 'or whatever title you get
vresarray = split(titlestr, ".")
arraybound = ubound(vresarray)
if arraybound = 0 then
msgbox "no extension"
asmtitle = titlestr
else
if vresarray(arraybound) = "sldasm" then
msgbox "assembly extension found"
asmtitle = left(titlestr, len(titlestr) - 7)
else
asmtitle = titlestr
end if
end if
msgbox asmtitle
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
edited: 02/18/2009 at 09:05 am by stavros antoniou
how about using josh's but changing the left statment
sub main()
name = application.sldworks.activedoc.gettitle()
name = left(name, len(name) - 7)
end sub
i'm editing this. i just realized that if there is not a period in the title which is caused by your explorer settings not showing the file extension that this would probably error and/or give the wrong result.
dan miel
edited: 02/18/2009 at 10:23 am by dan miel
originally posted by: dan miel
how about using josh's but changing the left statment
sub main()
name = application.sldworks.activedoc.gettitle()
name = left(name, len(name) - 7)
end sub
dan miel
you could but if the document does not have an extension (maybe because it was hidden) then the return string will be erroneous.
--stav.
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
rather than wrestling with the "hide extension for known file types", i prefer to parse the entire path. this can be had from modeldoc2.getpathname. it will always include the extension. filenames may not contain a "\", so you can easily get the filename with extension by splitting with "\" as a separator. then you can either split again with "." and rebuild the name or you can find the position of the last "." using instrrev. or you can just assume that the extension has 6 characters and strip off the last 7 per dan's post.
i'll get you eh steve, if it's the last thing i dooooo!
model.getpathname fails with new not saved assembly
and what about this one using "\":
sub main ()
dim a as string
dim atext() as string, s as string
dim name as string
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
set swapp = createobject("sldworks.application")
set swmodel = swapp.activedoc
a = swmodel.getpathname
atext = split(a, "\")
s = atext(ubound(atext))
name = left(s, instr(s, ".") - 1) 'name=name of the modeldoc2
end sub
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】inserting and mating parts in an assembly yang686526 SolidWorks二次开发 0 2009-04-12 06:43 PM


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


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