+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Senior Member ILoveMadoka's Avatar
    Using
    Solidworks 2013
    Join Date
    Oct 2008
    Posts
    332

    Wink Solidworks Macros - 2 Part Question

    Registered forum members do not see this ad.

    1) Are there any SW API Power Users Here?
    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!!

  2. #2
    Super Member stevsmith's Avatar
    Computer Details
    stevsmith's Computer Details
    Operating System:
    Windows 7 (64bit)
    Discipline
    Mechanical
    stevsmith's Discipline Details
    Occupation
    High Plains Drifter
    Discipline
    Mechanical
    Using
    Solidworks 2015
    Join Date
    Apr 2008
    Location
    Largs, Scotland
    Posts
    1,072

    Default

    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.
    "The fear of death follows from the fear of life. A man who lives fully is prepared to die at any time"

    SolidWorks | AutoCAD | Creo

  3. #3
    Forum Deity shift1313's Avatar
    Using
    not applicable
    Join Date
    Sep 2008
    Location
    VA
    Posts
    3,249

    Default

    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.
    Www.cadsharp.com
    Matt - Certified Solidworks Expert -Advanced Surfacing, Mold Tool and Sheet Metal Specialist
    Current Software: SolidWorks17,Mastercam2017, fusion360, Inventor 2017, HSMworksUltimate
    http://www.solidbox.tv Free and Paid Tutorials for Solidworks, Mastercam and Fusion360
    http://www.mysolidbox.com/ CAD and CAM optimized workstations and laptops

  4. #4
    Senior Member ILoveMadoka's Avatar
    Using
    Solidworks 2013
    Join Date
    Oct 2008
    Posts
    332

    Default

    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

  5. #5
    Senior Member ILoveMadoka's Avatar
    Using
    Solidworks 2013
    Join Date
    Oct 2008
    Posts
    332

    Default

    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

  6. #6
    Forum Deity shift1313's Avatar
    Using
    not applicable
    Join Date
    Sep 2008
    Location
    VA
    Posts
    3,249

    Default

    Record macro puts more emphasis on cursor position than the true selection set. Ill try to look into it tonight. No promises
    Matt - Certified Solidworks Expert -Advanced Surfacing, Mold Tool and Sheet Metal Specialist
    Current Software: SolidWorks17,Mastercam2017, fusion360, Inventor 2017, HSMworksUltimate
    http://www.solidbox.tv Free and Paid Tutorials for Solidworks, Mastercam and Fusion360
    http://www.mysolidbox.com/ CAD and CAM optimized workstations and laptops

  7. #7
    Forum Deity shift1313's Avatar
    Using
    not applicable
    Join Date
    Sep 2008
    Location
    VA
    Posts
    3,249

    Default

    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
    Matt - Certified Solidworks Expert -Advanced Surfacing, Mold Tool and Sheet Metal Specialist
    Current Software: SolidWorks17,Mastercam2017, fusion360, Inventor 2017, HSMworksUltimate
    http://www.solidbox.tv Free and Paid Tutorials for Solidworks, Mastercam and Fusion360
    http://www.mysolidbox.com/ CAD and CAM optimized workstations and laptops

  8. #8
    Forum Deity shift1313's Avatar
    Using
    not applicable
    Join Date
    Sep 2008
    Location
    VA
    Posts
    3,249

    Default

    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.
    Attached Files
    Matt - Certified Solidworks Expert -Advanced Surfacing, Mold Tool and Sheet Metal Specialist
    Current Software: SolidWorks17,Mastercam2017, fusion360, Inventor 2017, HSMworksUltimate
    http://www.solidbox.tv Free and Paid Tutorials for Solidworks, Mastercam and Fusion360
    http://www.mysolidbox.com/ CAD and CAM optimized workstations and laptops

  9. #9
    Senior Member ILoveMadoka's Avatar
    Using
    Solidworks 2013
    Join Date
    Oct 2008
    Posts
    332

    Default

    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

  10. #10
    Forum Deity shift1313's Avatar
    Using
    not applicable
    Join Date
    Sep 2008
    Location
    VA
    Posts
    3,249

    Default

    Registered forum members do not see this ad.

    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.
    Matt - Certified Solidworks Expert -Advanced Surfacing, Mold Tool and Sheet Metal Specialist
    Current Software: SolidWorks17,Mastercam2017, fusion360, Inventor 2017, HSMworksUltimate
    http://www.solidbox.tv Free and Paid Tutorials for Solidworks, Mastercam and Fusion360
    http://www.mysolidbox.com/ CAD and CAM optimized workstations and laptops

Similar Threads

  1. Automation/Macros in drawings, templates, and part making
    By andar424 in forum Autodesk Inventor
    Replies: 0
    Last Post: 16th Feb 2015, 05:48 am
  2. Replies: 1
    Last Post: 25th Jun 2014, 08:35 pm
  3. Need some idea about how to do a plastic part in solidworks
    By sukhbirsingh91 in forum SolidWorks
    Replies: 4
    Last Post: 22nd Nov 2013, 02:38 pm
  4. SolidWorks API - Copy part name text
    By hayyagahoy in forum SolidWorks
    Replies: 4
    Last Post: 4th Oct 2013, 05:54 pm
  5. Good Question: Action Macros and VBA
    By AutoCAD Insider in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 13th May 2008, 06:40 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts