New Drawing Macro Help

I've got a macro question, I'm trying to make a macro that creates a new drawing file from an assembly file, I am then wanting it to generate various views placed in the same place. The last couple of lines are the problem, this macro places views of a certain file but if I open up a different assembly and make a drawing it places the views from the first assembly. Any help would be greatly appreciated. I know very little about Visual Basic, I'm currently taking a class in it but I haven't learned much yet. I'm looking for the command to use that selects the currently opened file name and puts it as a variable to use in the drawing view creation. Also is there any way to make a macro to do the selected dimension. For example a macro to change a dimension that is selected to mm from inches?

' ****************************************************************************** ' D:\DOCUME~1\LUCASL~1\LOCALS~1\Temp\swx4356\Macro1.swb - macro recorded on 05/28/06 by ********************* ' ****************************************************************************** Dim swApp As Object Dim Part As Object Dim SelMgr As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim Feature As Object

Sub main()

Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Set SelMgr = Part.SelectionManager swApp.ActiveDoc.ActiveView.FrameLeft = 0 swApp.ActiveDoc.ActiveView.FrameTop = 0 swApp.ActiveDoc.ActiveView.FrameState = 1 Set Part = swApp.NewDocument("Drawing Template File Path", 12, 0.2794,

0.4318) Set Part = swApp.ActiveDoc Set SelMgr = Part.SelectionManager Part.ViewZoomtofit2 boolstatus = Part.ActivateView("Drawing View1") boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.1173527476636, 0.1787637757009, 0, False, 0, Nothing, 0) Part.EditDelete Dim DrawView As Object Set DrawView = Part.CreateDrawViewFromModelView2("Assembly File Path", "*Isometric", 0.1297821308411, 0.1627831401869, 0) boolstatus = Part.ActivateView("Drawing View4") Set DrawView = Part.CreateDrawViewFromModelView2("Assebly File Path", "*Front", 0.294915364486, 0.1610075140187, 0) Part.ClearSelection2 True End Sub

Lucas Laverman Senior, Mechanical Engineering

Reply to
lavs23
Loading thread data ...

Well it sounds like what you are trying to do is already covered by existing SolidWorks functionality. It is called "predefined views" and you can save a drawing of this type as a template. Take the drawing you want and do insert -> drawing view -> predefined. Place it on drawing sheet and then fill out the property manager information. Now to populate all your drawing views just drag a part/assembly/whatever into the drawing and all the views will populate. Or you can rmb a predefined view and choose "insert model."

In regards to your code: What I imagine you want to happen is that user opens an assembly then runs the macro and the drawing gets created. To do this define your assembly and part variables separately. I didn't test this, but the below code should pretty much do what you want. Essentially the currently open document is assumed to be your assembly. I store it in an Assembly variable. Then I create a drawing and store its information in the Drawing variable. By separating them I don't mix up information.

Dim swApp As Object Dim Assembly As Object Dim Drawing As Object Dim SelMgr As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim Feature As Object Dim DrawView As Object

Sub main()

Set swApp = Application.SldWorks Set Assembly = swApp.ActiveDoc Set SelMgr = Assembly.SelectionManager Set Drawing = swApp.NewDocument("Drawing Template File Path", 12,

0.2794, 0.4318)

boolstatus = Drawing .Extension.SelectByID2("Drawing View1", "DRAWINGVIEW",

0.1173527476636, 0.1787637757009, 0, False, 0, Nothing, 0) Drawing.EditDelete

Set DrawView = Drawing .CreateDrawViewFromModelView2(Assembly.GetPathName, "*Isometric", 0.1297821308411, 0.1627831401869, 0)

Set DrawView = Drawing.CreateDrawViewFromModelView2(Assembly.GetPathName, "*Front", 0.294915364486, 0.1610075140187, 0) Drawing.ClearSelection2 True End Sub

Reply to
Mr. Who

Dimensions are tricky. You would use:

DisplayDimension::SetUnits

I would recommend looking at some examples in API help to figure it out.

Reply to
Mr. Who

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.