API -- Change dimension in part without opening it?

Discussion in 'SolidWorks' started by plh, Dec 4, 2006.

  1. plh

    plh Guest

    What I want to do is locate a part file on the system by name, including folder,
    save that under a new name, and with that newly saved part, change a dimension
    and save it, without opening anything.
    Then I want to locate a drawing file on the system by name, save it under a new
    name, and assign the newly saved part file to it as the reference.
    Is this possible? If so, how do I get started? I can get this to work if the
    parts and drawings are opened, and I can open them with API, but I want to go
    further and do it without opening them in the first place, to make the process
    go faster.
    Thank You,
    -plh
     
    plh, Dec 4, 2006
    #1
  2. plh

    TOP Guest

    I can tell you why you might not want to do this. If you change the
    dimension without rebuilding and saving the drawing will open in
    SWViewer with the old dimension even though you have given it a new
    filename. I have seen this kind of thing get to mfg. It ain't pretty.
     
    TOP, Dec 5, 2006
    #2
  3. plh

    plh Guest

    I am aware of that limitation, thanks. What I am going to do is bring the
    drawing up (in SW) *after* A have done all the "silent" changes, it will rebuild
    then (see original post)
    Thanx,
    -plh
     
    plh, Dec 5, 2006
    #3
  4. plh

    customsolids Guest

    You can do all this EXCEPT change the dimension while files are closed.
    There might be a somewhat clumsy work-around if you built your parts
    to include an externally linked design table, or a macro feature that
    would read a dimension from custom properties or other external source
    each time the part rebuilds. Short of extraordinary measures like
    these, however, a dimensional change would necessitate a file-open on
    the part or assembly model (not necessarily the drawing that references
    them).

    HTH,
    BDB
     
    customsolids, Dec 6, 2006
    #4
  5. plh

    TOP Guest

    If you opened just the drawing and the dimension was imported you just
    change it there.
     
    TOP, Dec 7, 2006
    #5
  6. plh

    customsolids Guest

    True enough. Still requires a file-open, which takes some time.
     
    customsolids, Dec 7, 2006
    #6
  7. plh

    customsolids Guest

    True enough. Still requires a file-open, which takes some time.
     
    customsolids, Dec 7, 2006
    #7
  8. plh

    TOP Guest

    Of course with SW saying you have the file open is a relative term.
    Just how open does it have to be? For example if you write directly to
    database or turn off visibility you minimize overhead related to
    interactive use while still capturing the important stuff.
     
    TOP, Dec 7, 2006
    #8
  9. plh

    plh Guest

    Hi,
    I have not looked at this thread in a while.
    The whole point of this project is to programatically clone parts with different
    "driver" dimensions with the end result of rapidly produced and consistent
    drawings. I am resigned to opening the drawings and parts. I now have the
    following sequence pretty good:
    Copy "base" drawing to new name. (using FileSystemObject)
    Open new drawing (Opendoc6)
    Open base part (OpenDoc6)
    Save base part under new name. (swModelDocExt.SaveAs)This causes to the drawing
    to refer to the correct part.
    The problem is that at the save as routine closes the part. I want to leave it
    open so that I can go in and programatically change the relevant dimension. I
    tried to reopen it (OpenDoc6) but nWarnings is returning 128 (& as of this time
    I don't know what that means) and I end up with the Drawing open, referencing
    the correct part, but the part closed. So, that is my current problem, can I
    prevent swModelDocExt.SaveAs from closing the part.
    Thank You,
    -plh

    PS:
    bolRetVal = swApp.SetCurrentWorkingDirectory(strHomeFolder)

    Set obFSO = CreateObject("Scripting.FileSystemObject")
    With obFSO

    If .FileExists(Me.txtFolder.Value & "\" & Me.txtPartNumber.Value & ".SLDPRT") _
    Or .FileExists(Me.txtFolder.Value & "\" & Me.txtPartNumber.Value & ".SLDDRW")
    Then
    'in case of overwrite make sure user wants to do that
    If MsgBox("File Exists! Want to Overwrite?", vbYesNo) <> 6 Then
    Me.txtFolder.Value = ""
    Me.txtPartNumber.Value = ""
    Exit Sub
    Else
    '.CopyFile strBasePart, Me.txtFolder.Value _
    '& "\" & Me.txtPartNumber.Value & ".SLDPRT"
    'copy the part to that folder

    .CopyFile strBaseDrawing, Me.txtFolder.Value _
    & "\" & Me.txtPartNumber.Value & ".SLDDRW"
    'copy the drawing to that folder

    End If
    Else
    .CopyFile strBaseDrawing, Me.txtFolder.Value _
    & "\" & Me.txtPartNumber.Value & ".SLDDRW"
    'copy the drawing to that folder
    End If
    End With



    strPartToReference = Me.txtFolder.Value & "\" & Me.txtPartNumber.Value &
    ".SLDPRT"
    'Me.txtFolder.Value & "\" & Me.txtPartNumber.Value & ".SLDPRT"
    strDrawingToOpen = Me.txtFolder.Value & "\" & Me.txtPartNumber.Value & ".SLDDRW"

    Set swDrawing = swApp.OpenDoc6(strDrawingToOpen, swDocDRAWING, _
    swOpenDocOptions_Silent, "", nErrors, nWarnings)
    If ReportNErrors(nErrors, nWarnings, strDrawingToOpen) = False Then Exit Sub
    'open the New drawing which will still reference the BASE part

    Set swPart = swApp.OpenDoc6(strBasePart, swDocPART, _
    swOpenDocOptions_Silent, "", nErrors, nWarnings)
    If ReportNErrors(nErrors, nWarnings, strBasePart) = False Then Exit Sub
    'open the BASE part

    bolRetVal = swApp.SetCurrentWorkingDirectory(Me.txtFolder.Value)

    Set swModelDocExt = swPart.Extension
    bolRetVal = swModelDocExt.SaveAs(strPartToReference, 0, swSaveAsOptions_Silent,
    Nothing, nErrors, nWarnings)
    If ReportNErrors(nErrors, nWarnings, strPartToReference) = False Then Exit Sub
    'do a save as in order to link the new part to th drawing

    Set swPart = swApp.OpenDoc6(strPartToReference, swDocPART, _
    0, "", nErrors, nWarnings)
    If ReportNErrors(nErrors, nWarnings, strPartToReference) = False Then Exit Sub
    'open the NEW part

    Set swPart = swApp.ActivateDoc2(strPartToReference, False, longstatus)
     
    plh, Dec 13, 2006
    #9
  10. plh

    plh Guest

    I was able to solve this by opening the part first then the drawing. For some
    reason that did it.
    -plh
     
    plh, Dec 13, 2006
    #10
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.