几何尺寸与公差论坛

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

【转帖】setting a custom property

[复制链接]
发表于 2009-4-13 14:14:18 | 显示全部楼层 |阅读模式
setting a custom property
i am sorry that this is such a basic question, but i am missing something here, and a search of the forum showed nothing. i am confused about how to set a custom property.
the api help file gives me;
retval = custompropertymanager.set ( fieldname, fieldvalue)
i am guessing that retval is just something that vba requires, and really isn't used for anything.
so, when i attempt the following code;
retval = custompropertymanager.set("partno", joespartno)
vba highlights the phrase custompropertymanager and says variable not defined.
what am i missing?
joe dunfee
sw 2009 sp3.0 windows xp
hp compaq dc5800 microtower
nvidia quadro fx 3700
if you have option explicit written at the top of the code file you need to define every variable before using it so that is usually for this error.
in your case it is because you have just written custompropertymanager.set, when custompropertymanager is a class/interface not a variable.
you must first get a custompropertymanager variable object from a part/asm/drawing using modeldoc2::extension::custompropertymanager("configname"), where "configname" is blank for custom properties, or a configuration name for configuration specific properties.
if you search the api help and click the example button you will find what you need. if you still struggle take a look at some of my macros
thanks luke for the effort. i tried to view your example, but the web site doesn't give me permission to view them.
i've searched in the api help files, but don't seem to be choosing the correct terms to show what you are saying.
i tried just adding your line to the code;
modeldoc2:: extension:: custompropertymanager ("")
but, vba replys "sub or function not defined" with the "extension" part highlighted.
joe dunfee
sw 2009 sp3.0 windows xp
hp compaq dc5800 microtower
nvidia quadro fx 3700
edited: 08/19/2008 at 11:01 am by joe dunfee
just create an account to download the macros it will help you.
and my line of code is coding terms not actual code, you cant just copy and paste things it will never work. get yourself an account on a6 (its free) and take a look at them.
well, i don't seem to be getting a handle on this. i put a few hours into this yesterday and today without any progress. we plan on buying a 3rd party book on sw, which will have an intro to vba for sw (though i have done some vba for autocad a few years ago). i haven't done any programming in sw with everything working right, and therefore not in a good position to do so when something is odd-ball.
joe dunfee
sw 2009 sp3.0 windows xp
hp compaq dc5800 microtower
nvidia quadro fx 3700
well i have written a book on just that if you are interested
hi joe,
you should buy a copy of luke's book it will help in getting to grips with the basics. i've found it to be a very good source of information.
declan.
i will definitely be getting a sw api related book. but, i did finally find a simple example of setting a custom property;
'****************************************************************
'
' config props.swb
' joe jones
' new hampshire cad .nhcad.com
' 03/09/98
'
' will write several custom properties to active configuration
' ***************************************************************
dim swapp as object
dim part as object
dim configuration as object
dim configname as string
dim retval as boolean
sub main()
set swapp = createobject ("sldworks.application")
set part = swapp.activedoc
set configuration = part.getactiveconfiguration
configname = configuration.name
' retval is true or false upon successful addcustominfo3 function
retval = part.deletecustominfo2 (configname, "drawnby")
retval = part.addcustominfo3 (configname, "drawnby", _
30, "joe jones")
' will insert todays date
retval = part.deletecustominfo2 (configname, "date")
retval = part.addcustominfo3 (configname, "date", 64, str(date))
retval = part.deletecustominfo2 (configname, "luckynumber")
retval = part.addcustominfo3 (configname, "luckynumber", _
3, 345.99)
retval = part.deletecustominfo2 (configname, "success")
retval = part.addcustominfo3 (configname, "success", 11, "yes")
end sub
---
joe dunfee
sw 2009 sp3.0 windows xp
hp compaq dc5800 microtower
nvidia quadro fx 3700
joe,
the examples given in the first place do exactly this using the up-to-date api, that example is very outdated and the api is obsolete
i had just come back to post that i discovered the program was out of date. the first example didn't work for me as i copied them, so it was apparent that i was missing something needed to make it work.
i need the book!
joe dunfee
sw 2009 sp3.0 windows xp
hp compaq dc5800 microtower
nvidia quadro fx 3700
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-22 23:41 , Processed in 0.035676 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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