×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

API to reload sheet template

API to reload sheet template

API to reload sheet template

(OP)
From time to time the company sheet formats get updated.  I was looking at creating a macro to automate the process up upgrading a drawing to the new version of the format (with the same file name).  However, on some drawings (seems random to me), SolidWorks does not allow a reload without convincing it I'm loading a new format (clicking another format and then reselecting the original in the sheet properties window).  This issue has been cropping up from time to time across multiple releases of SW.

Anyway, it's been annoying, but ignorable problem.  However, now that I'm trying to automatic the process of sheet format updating, this has become a show stopper.  Does anyone know a way to force SW to reload a format via API?  SetupSheet4 does nothing but mimic the problem that occurs manually and I can't find a API workaround.

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: API to reload sheet template

(OP)
Lenny's macro still employs SetupSheet4.  I've talked to my VAR. The prelimary evaluation of the problem is that the original sheet format used to be in another directory, but with the same file name.  For some reason, SolidWorks doesn't bother looking at the path if it sees the file name is the same from the original sheet format used.  When one tries to reload the sheet and it doesn't find the original file but still finds the new location, it just ignores the file at the new location all together and pretends it reloads the format correctly, even though it doesn't do anything at all.  To compound the issue, in the API, SetupSheet4 gives a TRUE result when it does this (meaning it thinks it did everything correctly if though it actually failed).

At this time, the only API workaround I can figure out is to tell SW to load a completely different format, then load the correct format from the new location., but that is a bit ridiculous.

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: API to reload sheet template

It may be ridiculous, but if it works .....

cheers

RE: API to reload sheet template

I made a bogus template. So in the macro, first I change to the bogus template (that is actually just blank, nothing drawn in it) and then I load in the desired template. Not the most efficient, but it does work. I think I even had to create a custom sheet size too, but I don't remember for sure.

Ken

RE: API to reload sheet template

(OP)
Yeah, that kinda what I ended up doing.  I just finished it actually.  I ran into a few issues originally, like I couldn't find any examples for Sheet.GetSize that worked and it errored out on everything I tried. (Anyone know how GetSize is supposed to work?)

However, with a few hacks around that and the first issue, I made a macro that:
1. identifies the sheet currently on the drawing
2. loads a default SW format of the same size
3. loads the new format of the correct size
4. adds the revision block

Issues I ran into:
1. SolidWorks doesn't reload a new sheet format by the same name as the drawing's current sheet format if the current sheet format is physically no longer where SW expects it, but SW still pretends to perform the reload.  Solution was to load a fake format first, then load the new desired format.
2. couldn't figure out how getsize works, so had to make a work around using the GetSheetName.  I had a surpizing issue with GetSheetName too where SolidWorks was changing the name it reads for the sheet format from normal upper/lower windows names to all lowercase.  Worked around that second issue with UCase.
3. found out that API methods for adding revision blocks uses a different "anchor point" than the manual method, making the default API method useless.  Workaround was finding out the X,Y location s and listing them in the code directly.  

Fun stuff when nothing works the way it is supposed at every step.  The resulting code is hella ugly, but it does work.

Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources