Jump to content
ILoveMadoka

Solidworks Macros - 2 Part Question

Recommended Posts

ILoveMadoka

1) Are there any SW API Power Users Here? :cry:

That could help modify macro code?

 

2) Are there any sites that anyone can recommend similar to CADTUTOR

specific to solidworks (More specifically Macro programming/editing)

I find a lot of blogs but not a lot of interactive type sites..

 

I know there are some experienced SW users here but I am trying to learn

more about Macro creation/modification.

 

Here is an example:

I have multiple details in a SW drawing that each have "Detail X" on one line

and "Scale 1:2" on the second line.

I have to make the "Detail" text one size, the "X" another size

and the "Scale 1:2" text a third size. (Not my idea! :?)

 

I recorded a macro highlighting each text portion and changing the text size

but when I run the macro on a new piece of text, it changes the entire text item

to each size in turn. These labels are identical so it seems easy enough but

not sure if a macro can do something of this nature in a single step.

 

Any help, links, etc is greatly appreciated!!

Share this post


Link to post
Share on other sites
stevsmith

It would be better to post this directly onto the Solidworks Community forums under the API section.

 

https://forum.solidworks.com/community/api

 

This is probably the best place to get your answer and the turn around time is usually pretty quick.

Your VAR may also be able to help out. Generally most of the VAR's I've worked with have someone capable of carrying out system programming.

Share this post


Link to post
Share on other sites
shift1313

First off recording macros is a waste of time unfortunately. The code sw spits out isnt very helpful. Ive made a few video series on the subject but im far from an expert. Keith rice at cadsharp is the best I know.

 

Your best line of defense is actually the help file. There are a lot of samples in there. But check out keiths website.

http://Www.cadsharp.com

Share this post


Link to post
Share on other sites
ILoveMadoka

The Solidworks API forum sucks!

Tons of questions, very little answers.

Once in a while everyone will jump one particular question but personally

I've had very little luck there..

So many begging for help with little or no response...

 

CADTUTOR blows that site away!

 

I just wish I could get some help with api programming here...

320

Share this post


Link to post
Share on other sites
ILoveMadoka

When all you have is a hammer, all your problems look like nails!!

 

I've had more luck recording than on the Solidworks Forum...

 

Considering Keith's Tutorials

 

 

 

 

325

Share this post


Link to post
Share on other sites
shift1313

Record macro puts more emphasis on cursor position than the true selection set. Ill try to look into it tonight. No promises

Share this post


Link to post
Share on other sites
shift1313

Okay so i dug into this a little. I need a little bit more information.

 

Is the note always the same?

Is the "X" a variable that changes per note?

Is the scale based on a selected view?

Are you manually entering these notes?

 

In Solidworks it only really knows there is a "note" with text. I don't think it can really differentiate between text inside of a note. You can have 3 different notes and group them together, but select each one individually or , and i think the better option, have the macro insert the note. The slight issue with this is that the InsertNewNote3 doesn't let you control the font on the fly, it uses the model document fonts so you would still need to use the FontPoints method. Both a member of IModelDoc2.

 

Some benefits to adding the note this way. You can select a drawing view from which the note would get the scale value already. You could automatically place 3 new notes and be able to select them as they are placed(in the macro) and scale them.

 

Of course you can make a macro that allows you to select one note, change it to size 1, then select the second note, size 2 and then the third note size 3.

 

I made a quick macro to allow you to preselect a note and have it rescale to an entered Point text size. The best way this can work is if you have 3 notes grouped together. A note for you, the rebuild is acting funny and i still have to manually rebuild the file. if i were to do this i would made a modeless dialog box that allowed me to select a note enter a text value and apply it all while the dialog was open.

 

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swDrawing As SldWorks.DrawingDoc

Dim swSelMgr As SldWorks.SelectionMgr

Dim swNote As SldWorks.Note

Dim swFont As Long

 

 

 

Sub main()

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

 

On Error Resume Next

 

swFont = InputBox("Enter Font Size")

 

Set swNote = swSelMgr.GetSelectedObject6(1, -1)

 

swNote.SetHeightInPoints (swFont)

 

swModel.Rebuild (swCurrentSheetDisp)

swModel.Rebuild (swForceRebuildAll)

 

 

End Sub

Share this post


Link to post
Share on other sites
shift1313

Okay, i couldn't live with the rebuild not working so i dug into a bit more. its an issue thats only happening in 2015. So i tweaked the code to ForceRebuild3 and the rebuild works. I also added a simple modeless userform so it can be open while you select text and apply. The Point size you enter in the box is applied to the currently selected text when you hit apply. Because of the way i wrote the code, even if you manually select text inside the box the entire text box is changed. Their might be a way to do just the text if you dig into the api help a bit more. You can use a bunch of different members of iNote interface like "Add Text" There are also returns for GetSelectedObject6, part of modeldoc2, that can return selected text with swSelSectionText or swSelSketchText, but i haven't played around with them and just don't have the time currently. I would love to know if its possible but with my current knowledge of drawings api i just dont know.

 

I attached my macro for you to use. feel free to modify it or do whatever you need with it. Nothing is locked.

ChangeNoteFont.zip

Share this post


Link to post
Share on other sites
ILoveMadoka

I ended up creating a block and just changing the name of the detail (and the scale if I need to..)

 

I did not get notification of your last two posts or I would have responded a lot sooner!!

 

The SW forum is a strange place.

 

They will write a complete program for one person

and rebuff the next person for wanting to have a program written for them.

Its hard to figure out the rules and expectations on there.

I will get lots of help on one post and no replies on another.. :-\

 

 

thank you

Share this post


Link to post
Share on other sites
shift1313

Glad you found a solution. FYI i talked to Keith since him and I are currently working together on a project. He confirmed that there is no way to select text inside of a note and change the font with a macro. So it would have to be done with my last macro where you have 3 notes and change them individually but link them in the drawing so they move as one. You can also make a macro to insert the note where you have some control over the Text but have a default text already filled in.

 

I left the SW forum many years ago, and even this one, just because i didn't have the time for it. Writing macros for API with SW is a somewhat specialized thing. Programmers make pretty good money doing it for clients so they usually don't give it away for free. I also make good money doing tech support etc but i do try to give back answering questions cause not everyone can afford me ;)

 

I turned off notifications but i try to check the SW forum once a day since i came back here a few weeks ago. If you decide to play around with my macro let me know if you have any issues or questions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×