Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB to Set an Item Selected 1

Status
Not open for further replies.

Tobin1

Petroleum
Nov 9, 2007
176
Howdy All,

I'm trying to create a note Group with a Macro. The "CreateGroup" method requires preselected objects. So I'm trying to Set a new item created in the Macro as a selected item. I've been experimenting with the attached Macro and have added comments to explain what I'm trying to do.

Can anybody look at this and show me a possible way to do this?

Thanks

Tobin Sparks
 
Replies continue below

Recommended for you

Here's a slight modification that will allow retrieval, regrouping, or restoring of balloon/note groups. As long as the balloon itself is not deleted and element notes have not been moved to other views, the group can be restored if it has been un-grouped and/or note elements deleted. Selecting any member of a balloon group will load the form with the note texts.

-handleman, CSWP (The new, easy test)
 
 http://files.engineering.com/getfile.aspx?folder=6ca002b7-52f3-473f-858d-287b19a8b08f&file=Make_Note_Group.swp
handleman,

Thanks very much for both of your replys. I'm sure you spent some time on them. I'll have to let this sink in a bit. "BallNote.GetAnnotation.Select True" will be very helpful and then there is all the other stuff.

Thanks again

Tobin Sparks
 
Hey, I enjoyed it. It was an interesting little challenge. I hope you don't mind that I extrapolated a bit about the direction you were headed. I figured this was related to a previous thread. Most of the code is for tweaking the UI. Sorry for the lack of comments! I'll try to explain a little what's going on.

Surprisingly, there doesn't seem to be anything in the API to determine if a note is part of an annotation group, or to find the members of an annotation group. The only things I could find related to groups were create, remove, and remove item. All of those work on the current selection set, so once you create a group and change the selection set there is no way to programmatically figure out what notes/balloons are part of that group. I had to sort of create my own method of retrieving the group members. That's what the stuff about SerialString is all about. Each annotation of a SW drawing has a unique name, which you can change programmatically. When creating a new balloon/note group, this macro generates a new "serial number", which is just a string that will be part of the name of each member of the group. Every serial number starts with "HandleNote" so that the program can later determine if any given note is part of a group. The numbers that follow are just the date and time (down to the hundredth of a second or so) that the group was created. That ensures that every serial number is unique. The members of the group are named with a prefix denoting which member they are, followed by the serial number. "Bl_" is the prefix for the balloon member, "Bt_" is the bottom note, etc. Once that creation process is completed, you have five notes (one of them being a balloon) with the same name except for the first two characters. This allows the program to later locate all the members of a particular group, even after closing the macro, closing the file, closing SW, etc. The members can even be found if the user un-groups the group.

All of the code in the NewSelectionNotify function is related to finding members of a group. In order to treat the entire group as a unit, this code runs every time the user changes the selection set. There are basically 3 possibilities when a user makes a selection. This is not the order that the macro checks in, but they are:

1. The selection set contains more than 1 item or it is a non-note item. In this case, the the "Add Note" button is disabled, and the macro does nothing.
2. The selection is a note that is a balloon, but that balloon is not already part of a group, determined by whether or not the string "HandleNote_" is part of the name. In that case, the "Add Note" button is enabled to allow the user to create a group for that balloon.
3. The selection is any member of an existing group (again determined by the presence of "HandleNote_" in the name). If this is the case, the macro then searches all annotations on the current sheet for the remaining members of the group, based on matching the entire serial number. A note object is set for each matching note found, based on the first two letters of the note name. These note objects will later be manipulated by the "Add Note" code. After the search, the macro checks to see if it found a balloon as part of the group. If there was no balloon (meaning the user at some point un-grouped and deleted the balloon), the macro stops. The reason for this is that the location of the balloon determines the locations of the notes. If the balloon is gone, the group is effectively lost. If the balloon is found, then the macro loads the text from whatever group members were found into the text boxes of the form and enables the "Add Note" button.

The "Add Note" code was modified to update any notes that were already existing. These existing notes were found back in the NewSelectionNotify code. Any notes that were missing (maybe un-grouped and deleted by the user) are re-created. Even if the text box is blank, a note is still created. I probably should have made it where a blank box actually creates a note with a single space rather than an entirely blank note so that the ugly "blank note" x-ed out box doesn't show up.

Hope that explanation helps a bit!

-handleman, CSWP (The new, easy test)
 
handleman,

WOW - do I ever have a lot to learn :) .
Later today I'm going to post another question related to this balloon note idea. It’s too complicated to just do now. Sometimes it takes me a while to figure out how to ask a "good" question, or is it ask a question "good" :) .

Thanks

Tobin Sparks
 
handleman,

I can't thank you enough for all your time and effort for the above.

I read through the code and the above post several times and a couple of times real slow :) . I can get some of what is going on, but, not enough to duplicate how it works. I hate to ask but - could you kinda dumb it down for me? Maybe show how it works with only one note position. There seems to be too much going for my feeble brain. I've only completed one VB beginner programming book and I'm not familiar with the use of the While structure. I'm also interested is understanding how the macro picks up on the users picks that are not macro events, like picking different balloons on the sheet. I read that VB is event driven and assumed (I know that's always a problem) that meant events within the macros form.
Anyway - I do need a simplified version - please.

Thanks


Tobin Sparks
 
Sorry for the late reply. I only got to get on my PC about an hour ago. I'll try to fix some comments in the code to explain exactly what's going on. In the meantime, I did make some improvements (Fixed event handling, made notes actually attach to same entity as balloon, added custom property linking, added an option to change size of note), so if anyone is interested in using this macro as-is, see the attached file. Clicking on the "link" button in the middle will insert a link to a custom property into the last active text box. The custom property is picked from a list. This list is entered in the initialization code of the custom property list form. You can change that list to suit your company's custom property list. You just have to make sure that the numbers in parenthesis are sequential and that the highest of those numbers matches the number in the Dim statement.



-handleman, CSWP (The new, easy test)
 
 http://files.engineering.com/getfile.aspx?folder=db75bc6d-2c52-4898-86e9-6922fdd7bfd3&file=Make_Note_Group.swp
handleman,

I really appreciate all your effort. I'm always surprised you reply. This project is probably going to take a while for me to finish. I'm still running SW2007 SP5.0. The first macro I downloaded from you worked just fine, but, the last one requires Sw2008 Libraries. Of course I can still read the code, and it looks very interesting.

Here at NOV we use the Custom Properties for only a few things, but they are considered critical.
They Are:
Description (This populates the Description field in the BOM)
Wt (This is used to calculate the weight and it is populated in a field on the drawing sheet)
Actual Wt (This is a field where the engineer can enter a weight that for some reason is known to be different than the calculated weight and it populates a field in the drawing that is outside the sheet border)
Units (This is the units the part or assembly is manufactured in - Like "Pair", "Each" or "Inches" ...)
Nothing from the Custom Properties shows up in the body of the drawing.

I understand other companies use Custom Properties in a different way. I have no experience with using Custom Properties other than described above. We only use balloons to point to an Item from the BOM on the drawing. It's just an identifier and sometimes for clarity it could include the Quantity of that Item, and occasionally a reference note.

Thanks Again


Tobin Sparks
 
I don't think it actually requires the 2008 libraries. Just un-check the 2008 references and check their 2007 counterparts. I'm pretty sure I didn't use anything that was new for 2008.

Here's a version with a few comments.

-handleman, CSWP (The new, easy test)
 
 http://files.engineering.com/getfile.aspx?folder=87b71a7b-1b6b-462e-8177-4823dbee3308&file=Make_Note_Group(WithComments).swp
handleman

Very nice - Thank You so much! It'll take me awhile to read through all of it.

Have a nice weekend :)

Thanks

Tobin Sparks
 
Howdy All!

This is a First Look at my macro to add a Reference note to a Balloon. It still has a lot of limitations, if you want to break it I'm sure you can. It also needs some graphics and a lot of other finishing touches.
I plan to use this as the skeleton to build on. So far I've only implemented a small portion of handleman's fantastic code.
But this is a start and I want to see if there is some fundamental reason this won't work on other machines.

Enjoy for now


Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=6e6e5812-78e2-49d5-befc-06d6a71123bb&file=Make_Note_Group.zip
handleman,

Sorry for the mix-up.
I would appreciate any comments you may have after looking this over.
I was able to implement most of the ideas that came from the basic codes that you provided.
I guess the one big thing I didn’t implement was the Serial Numbering of all the entities that the code would create.
Although I think that is an ingenious idea at this point I’ve left it so the user can just interact with the entities on the SolidWorks Sheet.
If I were to go one step further and make this a SolidWorks Add-In type macro I would like to implement that ability.

Thanks for all your valuable help

Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=1aa1f00b-e257-475d-8192-f4da6e69c3cb&file=BalloonNote.zip
Not sure what you meant by "mix-up". But whatever sort of grievous offense it was I will bestow my favor upon you and grant forgiveness. ;-)

Conceptually it looks pretty good. I don't really have time right now to go very deep into it. You certainly put a lot of time into setting up the text locations! One little bitty thing - You may not want to have the property link text contain the property name by default. If the user is going to be grouping this type of information with a balloon on a regular basis, that is probably not needed. For example, if the user regularly links to the material on all balloons then they won't need it to say "Material: AISI 4140". Just the value of "AISI 4140" would most likely do.

The serial number thing was mostly fluff. It was an interesting challenge to see if I could create something and then find it again even after rebuilds and across sessions or even PCs.

-handleman, CSWP (The new, easy test)
 
handleman,

Good thing you're forgiving :) . I often need it :) .

I'm going to assume (I know, I know) anybody that will be using the Linked Property feature will be able to edit the code to there particular needs. I just wanted to make it so some text would display if someone decided to "play" with it. If they inserted a linked property that didn't have a link nothing would appear and it looks like nothing happened. Its not easy to actually pick it to delete it if there is no text displayed.

I certainly didn't want to sound like I was expecting a quick response or something - Just looking for any big NO NO's that you might notice - whenever you get a chance.

P.S. I just noticed the forum reply box is spell checking as I type - didn't notice that before.

Thanks again for all your help

Tobin Sparks
 
The spell checking is due to FireFox, I believe, rather than Eng-Tips. At least it is for me. If I un-check that option in FireFox the red underlining goes away. Maybe IE added that if that's what you're using.

Good point about the empty property values.



-handleman, CSWP (The new, easy test)
 
handleman,

Yep it's Firefox doing the spell checking- just loaded it yesterday and today I'm glad I did :) .

Thanks Again

Tobin Sparks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor