Help with VB Macro code
Help with VB Macro code
(OP)
Howdy!
I’m just beginning to learn a bit about the SW API. In the past I used AutoLISP in AutoCAD for productivity enhancements. But I didn’t get into VB at the time. I’ve been using SW daily for a little over a year now. I downloaded a few nice SW Macro’s and recorded a couple of my own.
I’ve found a Macro (AddViewLabel) that is very close to something that would help me label views the way I need to more efficiently. AddViewLabel is a collaborative effort by Matthew Lorono and Regg. I contacted Mr. Lorono to discuss an addition to the code. He’s agreeable with trying to add something to the code.
I need to change the view label’s because, as I’m sure you are all aware, SW uses only one text size for both lines of the view label it produces. I need the last line (the scale) to be a smaller text size than the other lines.
I’d like to change the AddViewLabel's code so it will do the following:
1) Use the SW “Section View Text” text size setting for the first two lines the Macro creates (Firster and Seconder).
Currently the Macro uses the SW “Note” text size setting for all text size:
[get note annotation object]
[Set swAnnotation = swNote.GetAnnotation]
2) Use the SW “Note” text size setting for the third line the Macro creates (showme).
The Macro is currently set up to use this text size for all text.
As I said I’m a beginner at this. I can look thru the code and figure out some of what is going on but not enough to figure out how to add the above function.
Can anybody help me with this?
I’m just beginning to learn a bit about the SW API. In the past I used AutoLISP in AutoCAD for productivity enhancements. But I didn’t get into VB at the time. I’ve been using SW daily for a little over a year now. I downloaded a few nice SW Macro’s and recorded a couple of my own.
I’ve found a Macro (AddViewLabel) that is very close to something that would help me label views the way I need to more efficiently. AddViewLabel is a collaborative effort by Matthew Lorono and Regg. I contacted Mr. Lorono to discuss an addition to the code. He’s agreeable with trying to add something to the code.
I need to change the view label’s because, as I’m sure you are all aware, SW uses only one text size for both lines of the view label it produces. I need the last line (the scale) to be a smaller text size than the other lines.
I’d like to change the AddViewLabel's code so it will do the following:
1) Use the SW “Section View Text” text size setting for the first two lines the Macro creates (Firster and Seconder).
Currently the Macro uses the SW “Note” text size setting for all text size:
[get note annotation object]
[Set swAnnotation = swNote.GetAnnotation]
2) Use the SW “Note” text size setting for the third line the Macro creates (showme).
The Macro is currently set up to use this text size for all text.
As I said I’m a beginner at this. I can look thru the code and figure out some of what is going on but not enough to figure out how to add the above function.
Can anybody help me with this?






RE: Help with VB Macro code
<FONT size=40>
(or some other more reasonable number). When you type that closing bracket ">", that text and brackets will disappear and all the following note text will change to size 40.
This is going to be basically what you want to do programmatically. In this macro, the note is actually created and added to the drawing in the Definer() subroutine using the command "InsertNote." The note text is the argument of that function. You will need to add the size tags into the text of the note being created. Since it is a note, it defaults to using the document note size setting. The simplest way to change the font size would be to just hard-code in the size values inside the size tags. It would be possible for the macro to read the document settings to determine the Section View Text and Note settings. However, actually reading in those values is probably a bit beyond where you are right now in your VBA/SW API experience. Let's just say you want the first and second lines to be 10 and the last line to be 5. You would modify each of the InsertNote commands in the Definer subroutine similar to:
CODE
Set swNote = Part.InsertNote(FieldFirst & Chr$(10) & FieldSecond & Chr$(10) & "SCALE: " & ScaleRatio(0) & ":" & ScaleRatio(1))
'New code line:
Set swNote = Part.InsertNote("<FONT size=10>" & FieldFirst & Chr$(10) & FieldSecond & Chr$(10) & "<FONT size=5>SCALE: " & ScaleRatio(0) & ":" & ScaleRatio(1))
All the note text will use the default settings except where modified by a text tag. All text after a tag is affected by that tag until changed by some new tag. Tags can change just about any aspect of a note. The tags do not actually affect the "Use Document Font" setting of the note. To remove all the tags and go back to default, just uncheck the box for "Use Document Font", deselect the note, reselect the note, and recheck the box.
RE: Help with VB Macro code
Thanks for the help!
This does help me to understand the code a little better. I will have to figure out how to make the Macro use the SW Note & Section View Label text. There's one more good suggestion from Mr. Lorono that needs to be added also. But this is very helpful to me.
I know I have a lot of basics to learn. I've downloaded a copy of Visual Basics Express and started reading thru the lessons.
Possibly you could answer a couple of questions, then I'll leave you alone or start a new post.
1) Could you point me to the location of a list of "invisible text tags" and related items?
2) In the AddViewLabel code what does <Chr$(10)> mean?
Thanks Again
RE: Help with VB Macro code
Take, for example, a diameter dimension. When you create a diameter dimension in a drawing, the drawing shows the dimension as "Ø50". If you look in the property manager, the text it shows is "<MOD-DIAM><DIM>". Those expressions with "<>" are what I'm calling "tags", because they're sort of similar to HTML tags. If you want to investigate these "tags" further, you can use this macro:
CODE
Dim OutPut As String
OutPut = "Displayed text:" & vbCrLf
OutPut = OutPut & Application.SldWorks.ActiveDoc.SelectionManager.GetSelectedObject6(1, -1).GetText
OutPut = OutPut & vbCrLf & vbCrLf & "Actual text:" & vbCrLf
OutPut = OutPut & Application.SldWorks.ActiveDoc.SelectionManager.GetSelectedObject6(1, -1).PropertyLinkedText
MsgBox OutPut
End Sub
To use this macro, create a note on a drawing. Then change portions of the note. Don't change the entire note using the Property Manager, use the popup text editing toolbar. Change fonts, font size, etc. for portions of the note. Add bullets/numbering. Insert symbols. Do whatever you want to see tags for. Then select the note and run the macro. You will see a message box that will match (as much as possible) the text as displayed on the screen along with the actual text that SW stores inside that note. That text contains the "tags" that instruct SW on how to actually display the note. The macro will error out if you do not have a note selected prior to running.
The Chr() function returns the character corresponding to the function argument in ASCII. Chr(10) is a linefeed. In this case it works the same as Chr(13) or vbCrLf - makes a string display as multiple lines on screen.
Unless you do lots of different drawings in which the Section View text size is different all the time, you can just use the <FONT size=X> tag, where X is whatever size fits your company standard for section view text size. You don't have to make the macro figure out the document setting for section view text size.
RE: Help with VB Macro code
Thanks so much for your response!
I still remember some of the AutoLISP text attribute commands (%%C, %%D, %%U, %%P, etc.). Unfortunately they are probably permanently etched in my brain, but not used much anymore.
Your Macro for extracting these from SW is very helpful. Just examining it helps me understand a little more about how to write my own VB code.
Apparently <Chr$(10)> is a little over my head still. I was just reading about arrays yesterday. I remember arrays from learning the REXX language many years ago. I'll keep reading.
Yes I can change the test size by changing the code, but, others in the company might be interested in this AddViewLabel tool. Even just for myself - I'd like to do this for a productivity enhancer. The least amount of fiddling around the better.
Thanks Again
RE: Help with VB Macro code
First line
Second line
Third line
you can't just put those directly in the code like:
CODE
Second line
Third line"
because each new line in the code window is interpreted as just that - a new line of code that must contain valid instructions. You have to use some other way to get those newlines into the string. This code uses Chr(10) as the carriage return:
CODE
The "&" symbol is the string contatenation operator. The "+" sign usually works too, but since it's also the addition operator you will rarely get unexpected results. It's best to use "&" when you have two different strings you want to stick together.
RE: Help with VB Macro code
Please let me know when you finish this Macro. I would love to get a copy of it.
Best,
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--“Coffee Talk” Mike Myers SNL
RE: Help with VB Macro code
CODE
Dim NoteHt As Double
SecViewLabHt = Application.SldWorks.ActiveDoc.GetUserPreferenceTextFormat(swDetailingSectionLabelTextFormat).CharHeight
NoteHt = Application.SldWorks.ActiveDoc.GetUserPreferenceTextFormat(swDetailingNoteTextFormat).CharHeight
You can then use these variables in place of hard-coding the numbers in. Using the same example line I posted before:
CODE
Set swNote = Part.InsertNote("<FONT size=" & SecViewLabHt & ">" & FieldFirst & Chr$(10) & FieldSecond & Chr$(10) & "<FONT size=" & NoteHt & ">SCALE: " & ScaleRatio(0) & ":" & ScaleRatio(1))
Each of those "Set swNote = Part.Inse......" lines corresponds to a different combination of the options on the form. You will have to modify each InsertNote command to size the notes the way you want them.
RE: Help with VB Macro code
OOHH!! Definitely got ya now. Chr$(10) is ASCII for a carriage return (linefeed). I probably won't forget that one for a while.
As for your second post I'll have to let it sink in a bit. I know I have to place this in just the right place in the code. I'll let you know when I figure it out.
macduf,
I'd be glad to let you know when we finish this.
RE: Help with VB Macro code
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--“Coffee Talk” Mike Myers SNL
RE: Help with VB Macro code
RE: Help with VB Macro code
That sounds good, I was actually thinking of projects with a database. Do you think that could be just as helpful?
RE: Help with VB Macro code
Attached is the SW Macro I’ve been working on. If you’re interested in beta testing give it a try and let me know of any issues.
This is my first real try at a SW Macro of this kind so I’m sure it could be “cleaned up” some. Let me know what you think.
Thanks
Tobin Sparks
www.nov.com
RE: Help with VB Macro code
I've not been able to get it to work on 2005. I'll try on 2007 latter today. When it is ready, I'd like to include it on my resources site, if you wish.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Help with VB Macro code
WOW! That would be fantastic! I hope it will work
Thanks
Tobin Sparks
www.nov.com
RE: Help with VB Macro code
RE: Help with VB Macro code
One thing....can you link the font back to the Section or a Detail, if you change it? I send a jpg in a moment.
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--“Coffee Talk” Mike Myers SNL
RE: Help with VB Macro code
Please note that I have a standing permission from a some individuals.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Help with VB Macro code
No this won't link to the settings. It's just a "dumb" note. To make it link back to the settings would be a whole different kind of Macro. Not sure if you could even call that a Macro
Thanks
Tobin Sparks
www.nov.com
RE: Help with VB Macro code
RE: Help with VB Macro code
Just had to ask. You did a great job sir!
Colin
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--“Coffee Talk” Mike Myers SNL
RE: Help with VB Macro code
Yes it's "freeware/public domain/distribute freely", I like the Open Source idea. Kind of hard to do anything else with .swb files
Tobin Sparks
www.nov.com
RE: Help with VB Macro code
I'm glad to here it's working for you. And quit with the "sir" c***
Thanks
Tobin Sparks
www.nov.com
RE: Help with VB Macro code
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Help with VB Macro code
<Which site?>
Is that question for Me? I don't understand.
Thanks
Tobin Sparks
www.nov.com
RE: Help with VB Macro code
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Help with VB Macro code
I've been playing with your macro. Some issues:
1. Remove unnecessary Reference libraries. One some systems, having certain unused libraries loaded will cause the macro not to function.
2. There appears to be an issue with the selection manager. I have issues with it recognizing the selected views more times than note (triggering error handling).
3. Should be a method within the form to change the font size and maybe even the type.
4. The form needs a little clean up. The error handling messages can have the name of the problem placed in the title of the windows, so you can clean those up too.
And, of course, the scale doesn't auto-update when the scale of the view changes, but you and I discussed that before. :)
And maybe add more detail about each of the default settings within the code and the help.
The form looks like a good first step and general concept.
When it does work, it works well. I like that you hide the actual label. I also like that it seems any actions taken by the macro can be undone with the standard SW Undo function.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Help with VB Macro code
These tiny enhancements really make a big difference to us guys and gals.
Colin
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--"Coffee Talk" Mike Myers SNL
RE: Help with VB Macro code
Thanks for your comments.
I obviously don't really know what I'm doing.
Thanks again - I appreciate your input.
Tobin
Tobin.Sparks@nov.com
RE: Help with VB Macro code
WOW - Thanks for your remarks. I gald this is working for you. This is just the beginning and I'll let you in on the coming enhancements to this learning project
Thanks
Tobin
Tobin.Sparks@nov.com
RE: Help with VB Macro code
I'll one up you. Even better would be if they allowed the user to adjust these factors in the first place. The fact that the section/detail labels are essentially locked out to the user is amazingly annoying.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Help with VB Macro code
That's what I kinda meant by my comment. My bad on my part. Yeah, it's really annoying. Another thing is really annoying is you can't add text to item balloons. I put numerous ER for this and SW never responded. I'm old school as far as drafting, I guess. I was taught a certain way to detail out drawings for aerospace, and SW locks you out of functionality as you mentioned.
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--"Coffee Talk" Mike Myers SNL
RE: Help with VB Macro code
Sorry it took so long to get to this -
Your statement "Another thing is really annoying is you can't add text to item balloons."
Could you elaborate on what you mean or send a screen shot showing what this might look like?
If it's what I'm thinking I'd like to try something
Thanks
Tobin
Tobin.Sparks@nov.com
RE: Help with VB Macro code
Have you tried the "Group" command? You can group a note and balloon together so that they stay together when moved.
RE: Help with VB Macro code
Yeah...I know about grouping, but it's a pain to do an extra step. Plus if ya edit or delete items, you have to ungroup and regroup.
Tobin1,
Let me see if I call dig up the stuff i sent to SW on this.
I'll be back in a bit.
Colin
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--"Coffee Talk" Mike Myers SNL
RE: Help with VB Macro code
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--"Coffee Talk" Mike Myers SNL
RE: Help with VB Macro code
That's pretty much what I imagined you were talking about. Years ago in AutoCAD I made myself a balloon block (I actually still have it) that had attributes that could be used the way you are describing. The block didn't have the top and bottom positions for the text though. I regularly used the right and left positions. Do you find you use the top and bottom positions?
I have an idea but this might take me awhile. I'll let you know what I come up with.
Thanks
Tobin
Tobin.Sparks@nov.com
RE: Help with VB Macro code
I use all the positions. The one that's irritating the most is not being able to put the text before the balloon because of the leader. Actually it would be cool if for one, SW to add the option we're talking about, and two....SW to add this to the auto ballooning and have it add the qty's i.e. 2X 6X 8X....when the option is selected.
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--"Coffee Talk" Mike Myers SNL
RE: Help with VB Macro code
I agree with you that this should be included in SW. It's almost like we're working with unfinished software. Of course there will always be room for improvement and I don't expect it to be even close to perfect, but this kind of thing just leaves ya wondering what they were thinking
I'm pretty sure whatever I come up with will not be able to put text between the leader and balloon, but, I'll look into it. That just means the user will have to choose a text position that won't interfere with the leader.
Thanks for giving me a little something new to work on
Tobin
Tobin.Sparks@nov.com
RE: Help with VB Macro code
Keep me posted if you have something for me to test.
Best,
Colin Fitzpatrick (aka Macduff)
Mechanical Designer
Solidworks 2007 SP 5.0
Dell 490 XP Pro SP 2
Xeon CPU 3.00 GHz 3.00 GB of RAM
nVida Quadro FX 3450 512 MB
I'm just a little verklempt. Talk amongst yourselves. I'll give you a topic. Pink Floyd, was neither Pink nor Floyd. Discuss!--"Coffee Talk" Mike Myers SNL
RE: Help with VB Macro code
I have some ideas for this macro. Let's talk. In the meantime, how's the section view labeller going?
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Help with VB Macro code
Great I'd like your input on the balloon project
Actually at this very moment (and since Monday evening) I haven't been able to work on anything in SW. It seems as though our IT people (yes they actually are people) have updated some Anti-Virus software that causes problems with SW. I've been in contact with our VAR and our IT people but it's not resolved yet.
I'll have to let you know when I make some progress on View Label.
What are your thoughts on the balloon? Do you know of any examples that might be helpful to look at?
Tobin
Tobin.Sparks@nov.com
RE: Help with VB Macro code
Then group these upon creation/or edit update. It's prolly a bit complex, but I imagine its do-able.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Help with VB Macro code
"radio buttons around a circle" I like it.
Do you think I could:
1) start with a default SW single balloon command with a leader then after allowing the two picks needed for that
2) add pre-entered text at a pre-selected position
3) then group it before the Macro ends?
Possibly the group will have to come in when text and one of the positions is picked.
It is a bit complex but as soon as I get SW running again I'll try some simple experiments.
What do you think about starting a new thread for this it's getting too far to scroll down and I thing we're off the subject?
Tobin
Tobin.Sparks@nov.com
RE: Help with VB Macro code
One thing about the selection methods, it is more intuitive to allow selection after the macro launches.
Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
RE: Help with VB Macro code
Go to www.3dcontentcentral.com, Macro Tab, Drawings Categories, for the latest release of Label View. This version is more user friendly than earlier versions as far as error handling and normal user expectations go (thanks fcsuper). I plan to make other improvements at a later date.
Thanks
Tobin Sparks
www.nov.com