几何尺寸与公差论坛

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

【转帖】linked sketch text now possible1 9sort of0

[复制链接]
发表于 2009-4-12 21:34:16 | 显示全部楼层 |阅读模式
linked sketch text now possible! (sort of)
attached is a file with some sketch text in sketch2. this text is linked to the thickness of the part. you can link the sketch text to anything you can get into the custom property. if you're into api and the weird fringe of sw, you can dig into how it works. otherwise, you can use this file as a sort of template as long as you only need to control one sketch text entity. there are four important things in it. you can delete anything else.
1. the custom property called "nameofsketchwithtext". its value should be the name of the sketch that contains only one sketch text entity. the sketch can contain any other geometry, construction geometry, etc. if you put your text in a sketch that is not called "sketch2", modify this custom property value to match.
2. the custom property called "text4sketch". whatever text it contains will go to the sketch text entity in the sketch named above.
3. the custom property called "code". this is where the magic is. peek behind the curtain if you must.
4. the equation "dummy" = "code".
note: this is lunatic fringe, unsupported, undocumented behavior. i tried to make it config-specific, but it crashed sw. it seems pretty stable with a single configuration though. enjoy!
i'll get you eh steve, if it's the last thing i dooooo!
neat trick......is there a macro feature or something here?
jason capriotti
jason.capriotti@thyssenkrupp.com
solidworks 2009 sp3.0
winxp 32 & 64bit
not exactly a macro feature. but there is a macro of sorts in there. you know that for years sw has supported vba in equations. you could do anything with vba that would fit in a single line of code. however, multiple independent statements could be strung together using the iif (inline if) function, since iif actually executes both the truepart and the falsepart, but only returns the value specified in the condition. the limitations were (a) can't use an "=" sign, (b) can't use any variables, and (c) no branching or looping since these require more than one line. however, solidworks 2009 introduced the capability to use custom property values in equations just by enclosing the custom property name in quotes. when sw parses the equation to solve it, the first thing it does is look through the equation for any custom property name in quotes. if it finds them, it replaces the name and quotes with the custom property value. now here's where it gets weird. when the sw equation syntax checker looks at the equation after the custom property substitution, it only looks at the first line of the custom property. as long as putting the first line into the equation makes it valid, sw will accept the equation. however, custom properties can contain multiple lines. the easiest way to do this is to type up multiple lines in notepad and then copy/paste into the custom properties dialog. somehow, when sw evaluates the equation all the lines of the custom property go to the vba engine. limitations a, b, and c above are gone. the only new limitations are (d) no blank lines, (e) no comments. in addition, you have to be very careful that your code doesn't trigger a rebuild every time it runs. then you'll have an endless loop and crash sw. you have to be able to exit the code if the change you want to make has already occurred.
i'll get you eh steve, if it's the last thing i dooooo!
but how did you get the text in the sketch to link to the dimension?
jason capriotti
jason.capriotti@thyssenkrupp.com
solidworks 2009 sp3.0
winxp 32 & 64bit
it is pretty roundabout. that dimension drives the custom property "text4sketch". you can see that in the custom properties dialog box. the equation "dummy" = "code" actually causes solidworks to execute vba code that is stored as text in the custom property called "code". you can view this code by copying it from the custom properties dialog and pasting it into notepad or something. the vba code:
1. looks at the custom property called "nameoftextwithsketch"
2. finds the sketch with that name
3. finds the first sketchtext entity in that sketch
4. checks to see if the text of that sketchtext entity matches the text of the "text4sketch" custom property.
5. important: if the text matches, exit the code.
6. if the text didn't match, edit the sketch, change the text, and exit editing the sketch.
the reason for #5 above is that you can't change the sketch text without editing the sketch. the action of editing the sketch causes a rebuild. without that check to see if the text already matches (and quitting code if it does), sw would go into an endless loop and crash.
another way to ensure an endless loop would be to link the sketch text to something that was affected by the sketch text. for example, if you had a "cut" feature using text that significantly altered the volume of the solid, then tried to link the text to the mass or volume. every change to the sketchtext would cause a change to the value driving sketchtext.
i'll get you eh steve, if it's the last thing i dooooo!
josh, you are the man for figuring this out.
wayne matus
texas engineering systems
solidworks needs a macro feature with a user interface (insert/feature/macro feature). the feature would appear in the tree and editing it would bring up the macro code editor. then we could do this kind of stuff easily.
has anyone ever created a macro feature?
jason capriotti
jason.capriotti@thyssenkrupp.com
solidworks 2009 sp3.0
winxp 32 & 64bit
i would tend to disagree with that. it's way too easy to kill sw with this kind of stuff. figuring out how to do the stuff you would want to do without triggering rebuilds isn't easy. of course, it's easy enough to write a .swp macro that'll crash sw to the desktop, but it seems to me like making it easy to add an app-killing feature would be more headache for sw than it's worth.
if i understand rightly, macro features that change geometry have to be done really low-level, like with the modeler. i don't think you can modify existing features or really do anything that triggers a rebuild inside of a macro feature.
i'll get you eh steve, if it's the last thing i dooooo!
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-1-11 10:55 , Processed in 0.039371 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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