A long time I wrote noting. Last month I had my first holiday vocation after 'working' , that's really precious to me.
Back to work, I have a mission to do some parameterized module design through the web. It means that, someone submit some params through their browsers, then the server renders the submitted params to the 3D model and changes the model, the users could retrieve the changed 3D models then.
I try to use ruby on rails and Solidworks to make a demo a demo of this application.
One difficult of this solution is how data flow through the application.
In my mind, firstly the user submit data to the server, then the server transfer the data to the ruby app. Secondly, ruby could manipulate the Solidworks through 'win32ole' and fill the data.
After Solidworks changes the model doc file and saves it to somewhere user could download from in the server.
Followed is the lib/solidworks.rb I wrote in my rails application:
1 require 'win32ole'
2
3 module ModelDoc
4 def saveAs(filename)
5 self.SaveAs3(filename, 0, 0)
6 end
7 def save
8 self.EditRebuild3
9 self.ViewZoomtofit2
10 self.Save2 false
11 end
12 def setValue(parameter, value = 0.01)
13 self.Parameter(parameter).SystemValue = value
14 end
15 def closeDoc(docName)
16 self.CloseDoc docName
17 end
18 end
19
20 module SldWorks
21 def openDoc(filename, filetype = 1)
22 self.OpenDoc(filename, filetype)
23 activeDoc
24 end
25 def activeDoc()
26 self.ActiveDoc().extend ModelDoc
27 end
28 def exit
29 self.ExitApp()
30 end
31 end
32
33 def solidworks
34 begin
35 @sldworks = WIN32OLE.connect('SldWorks.Application')
36 rescue WIN32OLERuntimeError
37 @sldworks = WIN32OLE.new('SldWorks.Application')
38 end
39 @sldworks.extend SldWorks
40 end
The most suck problem to use Soildworks API is the pointer params, most APIs have parameters like followed:
OpenDoc6 ( filename, type, options, configuration, &Errors, &Warnings )
&Errors and &Warnings are pointer type, but Ruby don't support pointer type that may be a big problem!
For some other suggestions look this guy's blog.