New Drawing Macro Help

Discussion in 'SolidWorks' started by lavs23, May 29, 2006.

  1. lavs23

    lavs23 Guest

    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
     
    lavs23, May 29, 2006
    #1
  2. lavs23

    Mr. Who Guest

    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
     
    Mr. Who, May 30, 2006
    #2
  3. lavs23

    Mr. Who Guest

    Dimensions are tricky. You would use:

    DisplayDimension::SetUnits

    I would recommend looking at some examples in API help to figure it out.
     
    Mr. Who, May 30, 2006
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.