New Topic: Python and Solidworks!

4859 views
Skip to first unread message

Markus Wankus

unread,
Dec 11, 2002, 11:07:36 PM12/11/02
to
Hi All.

How many of you are familiar with Python? Those of you who are, did you know it is pretty much a no-brainer to use it
to script Solidworks through COM with the win32 extensions from Mark Hammond? This means super-easy scripting of
the API, and with the use of wxPython (the windowing toolkit) you can do full-on GUI stuff just as easy.

Why, you may ask? Well, first of all - it is totally free (Open Source). Secondly, it is 100% interpreted, so you can make
a change to your GUI application, with no need to re-compile, re-install, whatever, just hit Go! (Actually, you can even
compile Python into .exe's if you want to as well). I have a few programs I wrote in VB a long time ago (the obligatory
Custom Properties, and a batch file converter) and some macros I am porting over to Python. I just started tonight, and
I must admit I don't know much about COM. I have a couple small issues yet to figure out, but I am already talking to
Solidworks with Python. I think this would be a awesome outlet for people who may not be "programmers" to do some
pretty powerful stuff.

If there is interest, I will try and help out as many people as possible in the days to come - provided they can help me out
as well. I would like to think I am pretty darn handy with Python, but when it comes to COM I am not. Luckily, once this
is working, the COM part of it just goes away, and you never see it.

Anyway, post if you are interested (especially if you are currently using Python with Solidworks), and let's have some
fun! If you don't know what Python is - check out www.python.org. Download it, and go through the tutorial. It is the
easiest (and best) programming language on the planet (well, most of us think so...).

Markus.


Johnny Geling remove: _removethis_

unread,
Dec 12, 2002, 3:29:45 AM12/12/02
to

That look very intresting. Could you keep us informed. It would make the
transition to Linux more easier. :)

Dale Dunn

unread,
Dec 12, 2002, 7:23:46 AM12/12/02
to
This is quite fascinating, as Python is a multiple-platform tool. But for a
Windows user, of a Windows-only app., what are the advantages of using
Python/COM over VB?

--
Dale Dunn
Design Engineer
www.jamestool.com

Markus Wankus

unread,
Dec 12, 2002, 9:07:35 AM12/12/02
to
On Thu, 12 Dec 2002 12:23:46 GMT, Dale Dunn <daledun...@jamestool.com> wrote:
> This is quite fascinating, as Python is a multiple-platform tool. But for a
> Windows user, of a Windows-only app., what are the advantages of using
> Python/COM over VB?

Well, I think the biggest reason (of many) is simply the ease and elegance of the language. I have tried to explain it
before, but the best thing is to try it for yourself (aw shit....I sound like JB...sorry). I DO have examples I could send
people, but you need to install Python first.

We use it at work (pure software development - nothing to do with CAD or Solidworks) for rapid prototyping, but are
finding that we are writing complete apps in it with ease. I talked to one developer at a games company who said they
are using Python for everything but the most complex graphics in their games now, and their codesize is sitting around
65% of the size of an equivalent game written in C++.

Anyway, simply put it is an elegant language, with beautiful syntax that most people find the best out there. There are
others who don't like it for exactly the reasons some people do like it. The biggest "preferential" barrier is that it is a
dynamically typed language. This means no declaring of variables. And you can reassign a variable to something
totally different later. It is similar to Java in that there is no memory management - garbage collection is done for you.
You don't have to destroy objects, maintain reference counts, etc. You just need to worry about programming. If you
aren't careful, you can pass the wrong type to a function however, and then if you try to iterate over a single integer
when you were expecting a list, and you don't catch the exception....well - then that's not good progrsmming anyway in
my opinion.

Finally - everyone I have spoken to (including myself....yes, I talk to myself) - when they tried it for the first time were
absolutely astounded that that the first *real* program they wrote "worked" the first try. The language is so natural and
easy.

I'll try to get some time to post some meaningful examples. Using CAD is my evening job, so I'll have to do what I can in
the evenings. I'll try to keep up with the newsgroup during the day.

And yes, it is completely cross-platform (much better then Java in this respect in my experience), so when Solidworks
does move to Linux.....hehe.

--
Markus.


Johnny Geling remove: _removethis_

unread,
Dec 12, 2002, 11:07:42 AM12/12/02
to

I would be delighted when you could send me some examples. Today I
installed the Python on Windows and have it already at home on Linux.


Johnny Geling
johnny.gelin...@chello.be

EvadeM

unread,
Dec 12, 2002, 12:42:10 PM12/12/02
to

"Markus Wankus" <markus...@hotmail.com> wrote in message
news:1103_10...@news1.on.sympatico.ca...

> I'll try to get some time to post some meaningful examples. Using CAD is
my evening job, so I'll have to do what I can in
> the evenings. I'll try to keep up with the newsgroup during the day.


I downloaded it last night and tried the tutorial a little bit. I have been
wanting to get into doing programs for SW but I have no experience at it. VB
was greek to me but so far Python seems pretty easy to learn. I would really
appreciate some examples too.

I only have one question. Where are the movies on their site? ;-)

Dave


Nick E.

unread,
Dec 12, 2002, 6:26:51 PM12/12/02
to

this would be very good.

unfortunately, i'm still struggling with PHP, and am not about to take on
another language at the moment. :)

regards,
nick e.

Markus Wankus wrote:

> Hi All.
>
> How many of you are familiar with Python? Those of you who are, did you
> know it is pretty much a no-brainer to use it
> to script Solidworks through COM with the win32 extensions from Mark
> Hammond? This means super-easy scripting of the API, and with the use of
> wxPython (the windowing toolkit) you can do full-on GUI stuff just as
> easy.

> Markus.

--
======================
Support Solidworks for Linux.
Go to http://www.cadsense.co.nz/SWXwish.htm
search for Linux and vote! It's currently #14!!
======================

Markus Wankus

unread,
Dec 13, 2002, 8:41:53 AM12/13/02
to
On Thu, 12 Dec 2002 17:26:51 -0600, "Nick E." <ni...@flyingpigs.com> wrote:
>
> this would be very good.
>
> unfortunately, i'm still struggling with PHP, and am not about to take on
> another language at the moment. :)

Well, PHP is cool. One of the first *cool* languages I found. But Python is cooler! And much easier to learn....

Markus


Mark Melvin

unread,
Dec 13, 2002, 8:47:35 AM12/13/02
to
On Thu, 12 Dec 2002 17:07:42 +0100, Johnny Geling remove: _removethis_

> I would be delighted when you could send me some examples. Today I
> installed the Python on Windows and have it already at home on Linux.
>

Well, last night I figured things out (with some help - Open Source is great...), and it all seems to be working properly
now. Quoting the guru who helped me out:

"Solidworks kinda sucks, in the same way notes does. Their object's provide
a type lib, but don't repsond to requests for that typelib at runtime."

Anyway, now I need to get some useful examples together. What are some things you guys do that are a HUGE pain
in the ass? Or maybe something you think would be cool to do that requires a lot of scripting or repetetive stuff? At
some point I will rewrite my Custom Properties GUI but that won't happen this wwek... ;o)

Markus.


Dale Dunn

unread,
Dec 13, 2002, 9:02:29 AM12/13/02
to

> Anyway, now I need to get some useful examples together. What are
> some things you guys do that are a HUGE pain in the ass? Or maybe
> something you think would be cool to do that requires a lot of
> scripting or repetetive stuff? At some point I will rewrite my Custom
> Properties GUI but that won't happen this wwek... ;o)
>
> Markus.

How about hiding update holders when SW starts? That sounds like a nice
demo-sized project.

Ricky Jordan

unread,
Dec 13, 2002, 10:19:15 AM12/13/02
to
Nick,

When you say that you are using PHP, I am assuming that you are using
PHP to access the API thru the COM library.

I am not a programmer, but I have some guys in our company that
program in PHP. We are thinking about purchasing PDM/Works Advanced
Server Extension so that we can access the vault thru the API to
display document information on PHP web pages. We could use the
WebPortal for this, but there is a desire to add this information to
an already existing PHP web page so that our field engineers will not
have to go to multiple pages for information access.

It sounds like this could be similar to what you are doing.

Are you having any success with this? Feel free to e-mail me directly
at the address shown below.

Best Regards,


Ricky Jordan
Mechanical Design Engineer
Certified SolidWorks Professional
Dynetics, Inc.
ricky....@REMOVETHISdynetics.com

"Nick E." <ni...@flyingpigs.com> wrote in message news:<b0-dnQ_iQbD...@giganews.com>...

bob zee

unread,
Dec 13, 2002, 10:48:59 AM12/13/02
to

"Dale Dunn" <daledun...@jamestool.com> wrote in message
news:Xns92E35B20EDBE5da...@65.24.2.12...

>
> How about hiding update holders when SW starts? That sounds like a nice
> demo-sized project.
>
> --
> Dale Dunn
> Design Engineer
> www.jamestool.com

bob z. will second that one. bob z. has often awakened in the night with
'update holders' floating above his bed...


--
bob z.
p.s.

http://www.euronet.nl/users/frankvw/IhateMS.html
http://bobzeerocks.tripod.com/aboutbob/
go to http://www.cadsense.co.nz/swxwish.htm
search for linux and vote - even if you don't like linux


Markus Wankus

unread,
Dec 13, 2002, 11:23:11 AM12/13/02
to
On Fri, 13 Dec 2002 10:48:59 -0500, bob zee <cam...@linuxmail.org> wrote:
>> How about hiding update holders when SW starts? That sounds like a nice
>> demo-sized project.
>>
>
> bob z. will second that one. bob z. has often awakened in the night with
> 'update holders' floating above his bed...
>

That sounds great, but now excuse my ignorance.....what is an Update
Holder?? I'm sure I use them everyday without knowing it, but can you
explain what it is?

(I guess I am not a hardcore SW guru...)


Thanks,
--
Markus

Dale Dunn

unread,
Dec 13, 2002, 11:34:21 AM12/13/02
to

> That sounds great, but now excuse my ignorance.....what is an Update
> Holder?? I'm sure I use them everyday without knowing it, but can you
> explain what it is?

You probably turn them off every day. They appear at the end of an
assembly's Feature Manager Tree. They represent when any In-Context
relationships are updated. They are widely held to have very limited
usefulness. They are on by default for every session of SW.

Markus Wankus

unread,
Dec 13, 2002, 11:39:09 AM12/13/02
to
On Fri, 13 Dec 2002 16:34:21 GMT, Dale Dunn <daledun...@jamestool.com> wrote:

> You probably turn them off every day. They appear at the end of an assembly's
> Feature Manager Tree. They represent when any In-Context relationships
> are updated. They are widely held to have very limited usefulness. They
> are on by default for every session of SW.
>

I assume this is not the same a fixing an In-Context part's external
references? I think I have seen them in my models...the "Update Sketch of
PartXXX" things hanging around at the bottom of the feature manager.
Hmmm...

--
Markus Wankus

Dale Dunn

unread,
Dec 13, 2002, 12:00:57 PM12/13/02
to

> I assume this is not the same a fixing an In-Context part's external
> references? I think I have seen them in my models...the "Update
> Sketch of PartXXX" things hanging around at the bottom of the feature
> manager. Hmmm...
>

Them's the ones.

Nick E.

unread,
Dec 13, 2002, 1:43:22 PM12/13/02
to
actually, i'm not doing anything SW right now (programmingly speaking).

just some PHP/MySQL/HTML stuff.

for now anyways.

regards,
nick e.

p.s. wow. #9. :)


Ricky Jordan wrote:

--

Markus Wankus

unread,
Dec 13, 2002, 7:46:56 PM12/13/02
to
On Fri, 13 Dec 2002 17:00:57 GMT, Dale Dunn <daledun...@jamestool.com> wrote:
>
> > I assume this is not the same a fixing an In-Context part's external
> > references? I think I have seen them in my models...the "Update
> > Sketch of PartXXX" things hanging around at the bottom of the feature
> > manager. Hmmm...
> >
>
> Them's the ones.


OK, sorry. But how do you go about turning them off? I cannot see any reference to something called an Update
Holder, and I have never turned one off. I recall locking External references on individual parts, but I am assuming this
is different from what you are referring to.

BTW, what version are you talking? I am still on 2001+.

--
Markus


Dale Dunn

unread,
Dec 14, 2002, 10:48:21 AM12/14/02
to
> OK, sorry. But how do you go about turning them off? I cannot see
> any reference to something called an Update Holder, and I have never
> turned one off. I recall locking External references on individual
> parts, but I am assuming this is different from what you are referring
> to.
>
> BTW, what version are you talking? I am still on 2001+.

They've been there since at least SW99, when I started. RMB on the assembly
name at the top of the FMT. "Hide Update holders" should be there. I did a
search in the API help and found that they go by a slightly different name
in the API (like other things). Anyhow, under swUserPreferenceToggle_e is
swIncontextFeatureHolderVisibility.

It's actually on my list of things I'd like to do with VB, I just need the
time to (figure out how) do it.

Markus Wankus

unread,
Dec 15, 2002, 6:48:50 PM12/15/02
to
On Sat, 14 Dec 2002 15:48:21 GMT, Dale Dunn <daledun...@jamestool.com> wrote:

> They've been there since at least SW99, when I started. RMB on the assembly
> name at the top of the FMT. "Hide Update holders" should be there. I did a
> search in the API help and found that they go by a slightly different name
> in the API (like other things). Anyhow, under swUserPreferenceToggle_e is
> swIncontextFeatureHolderVisibility.
>
> It's actually on my list of things I'd like to do with VB, I just need the
> time to (figure out how) do it.

Ah, OK. No problem - done and done. However, I had a pretty cool idea the other day, which I am working on
implementing. I am going to post the Python stuff and put together a tutorial-type webpage as soon as I finish up. I
hope you will all be very impressed....

---
Markus.

P.S. Nice website by the way, Dale. Very clean. Tell whoever did it I like it a lot.

Dale Dunn

unread,
Dec 15, 2002, 9:08:05 PM12/15/02
to

> P.S. Nice website by the way, Dale. Very clean. Tell whoever did it
> I like it a lot.

Thanks. Now I'll have to go look at it. I haven't actually checked it out
is a couple years....Oh that's interesting. Apparently, I'll have to find
out who's responsible for maintaining that thing.

Johnny Geling

unread,
Dec 16, 2002, 5:58:13 PM12/16/02
to
Markus Wankus wrote:

Keep us (me) informed.

Dale Dunn

unread,
Dec 17, 2002, 11:38:38 AM12/17/02
to
Looks like they've got it fixed now...

shuai.s...@gmail.com

unread,
Jul 23, 2012, 4:49:33 AM7/23/12
to
Hi Markus,
I am trying to using solidworks with python, do you have small example like import some XYZ point, then generate surface from lines, then generate body from surface. I just don't know how to start, i have installed python, do i need some other things?

moyshe...@gmail.com

unread,
Oct 9, 2012, 6:16:04 AM10/9/12
to
El lunes, 23 de julio de 2012 11:49:33 UTC+3, shuai.s...@gmail.com escribió:
> Hi Markus,
>
> I am trying to using solidworks with python, do you have small example like import some XYZ point, then generate surface from lines, then generate body from surface. I just don't know how to start, i have installed python, do i need some other things?

i will love to know if you work with pyhton + solidworks

actually looking forward to start working also with!

best

Moshe

p.s

please let me know if you find something!


s.sevee...@gmail.com

unread,
Sep 22, 2013, 7:46:56 AM9/22/13
to
This may not be useful, but http://www.freecadweb.org/ is a open source fully python scriptable CAD, in early but active development.

Senthil

v.samm...@gmail.com

unread,
Aug 3, 2018, 10:15:39 AM8/3/18
to
Hi Markus,
I am working on a Fan design. I wrote a code in Python for the estimation of the Fan geometry by using the classic design parameters, flow rate/pressure rise/rotational speed. Now I would like to modify the code in a way this can built the different Fan parts by using SolidWorks.
I think I am in the right Forum. Isn't it?
If yes, could you please send me some references, tutorials or some example where to start for my new project?
Thank you in advance!
Best regards,
Vincenzo


On Thursday, 12 December 2002 04:07:36 UTC, Markus Wankus wrote:
> Hi All.
>
> How many of you are familiar with Python? Those of you who are, did you know it is pretty much a no-brainer to use it
> to script Solidworks through COM with the win32 extensions from Mark Hammond? This means super-easy scripting of
> the API, and with the use of wxPython (the windowing toolkit) you can do full-on GUI stuff just as easy.
>
Reply all
Reply to author
Forward
0 new messages