Macro to copy "Description" custom property to clipboard.

Discussion in 'SolidWorks' started by SW Monkey, Jun 9, 2004.

  1. SW Monkey

    SW Monkey Guest

    I need to input the description manually into our PDM system until we
    get some scripting written. Does anyone know how I can copy the
    "Description" custom property of a model into the windows clipboard?
    This would allow me to 1. Open a model 2. Run the macro 3. Paste the
    description in the description field in PDM card.

    We use Smarteam for PDM, but we are waiting on the next upgrade which
    should have new scripting to transfer the description automatically.
     
    SW Monkey, Jun 9, 2004
    #1
  2. Just off the top of my head try this. In Windoze Explorer right click on the
    file, go to properties, go to custom tab, click on "description" in
    properties box, right click in value and select all, copy, then paste. Yes I
    now it's a lot of clicking but at least you don't have to open every file.
    Hope it helps.

    Matt B.
     
    Matthew A. Bush, Jun 9, 2004
    #2
  3. Quick search of the help I came up with this.

    Create a user form with a text box
    add code to the user form so it will extract the description and put it in
    the text box
    say it is Textbox1
    add these lines

    TextBox1.SelStart = 0
    TextBox1.SelLength = TextBox1.TextLength
    TextBox1.Copy
    End

    Corey
     
    Corey Scheich, Jun 9, 2004
    #3
  4. SW Monkey

    SW Monkey Guest

    Sounds like that would work, but what is the code to get the
    "Description" into the textbox?
     
    SW Monkey, Jun 10, 2004
    #4
  5. Try Model.CustomInfo2("", "Description")

    This will get the Description property for the document. If you want a
    specific configuration, just pass it instead of the empty string.
     
    Evan T. Basalik, Jun 10, 2004
    #5
  6. SW Monkey

    SW Monkey Guest

    I tried that, but I keep getting an error that something is missing.


    Anyone pretty good with VB that can whip up the code pretty quick? It
    seems like something very simple to do, but I cant figure it out :)

    Thanks :)
     
    SW Monkey, Jun 11, 2004
    #6
  7. Here is some code I had lying around it was for a different purpose but it
    is similar

    Private Sub UserForm_Initialize()
    'code created by Corey Scheich
    Dim ThisSheet As SldWorks.Sheet
    Dim ThisView As SldWorks.View
    Dim ThisViewName As String
    Dim ModelName As String
    Dim ThisModel As SldWorks.ModelDoc2
    Dim Description As String
    Dim CustomInfoNms() As String
    Dim Count As Long
    Dim swDrw As SldWorks.DrawingDoc
    Dim swApp As SldWorks.SldWorks

    Set swApp = Application.SldWorks
    Set swDrw = swApp.ActiveDoc

    Set ThisSheet = swDrw.GetCurrentSheet
    ThisViewName = ThisSheet.CustomPropertyView
    Set ThisView = swDrw.GetFirstView

    Do While Not ThisView Is Nothing
    If ThisViewName = ThisView.Name Then
    Exit Do
    End If
    Set ThisView = ThisView.GetNextView
    Loop

    If ThisView Is Nothing Then
    Set ThisView = swDrw.GetFirstView
    ModelName = ThisView.GetReferencedModelName
    While ModelName = "" And Not ThisView Is Nothing
    Set ThisView = ThisView.GetNextView
    If ThisView Is Nothing Then Exit Sub
    ModelName = ThisView.GetReferencedModelName
    Wend
    If ThisView Is Nothing Then Exit Sub
    End If
    Set ThisModel = swApp.GetOpenDocumentByName(ModelName)

    CustomInfoNms = ThisModel.GetCustomInfoNames2("")
    Count = 0
    Description = ""
    For Count = 0 To UBound(CustomInfoNms)
    If VBA.LCase(CustomInfoNms(Count)) = "description" Then
    Description = ThisModel.GetCustomInfoValue("",
    CustomInfoNms(Count))
    Exit For
    End If
    Next

    UserForm1.TextBox1 = Description
    TextBox1.SelStart = 0
    TextBox1.SelLength = TextBox1.TextLength
    TextBox1.Copy
    End
    End Sub

    I just tested this and it works
    You have to create a form named Userform1
    and a text box named TextBox1

    The first user form and textbox you create should be named this by default

    then in the code for the userform add the code above you will never see the
    form when the code runs

    Regards,

    Corey Scheich
     
    Corey Scheich, Jun 11, 2004
    #7
  8. Oh yeah that code is meant to be used from a drawing. You will have to
    strip it to use it from the model. Or edit it to check wether it is in a
    drawing or a model when you run it.

    Corey
     
    Corey Scheich, Jun 11, 2004
    #8
  9. SW Monkey

    SW Monkey Guest

    Thanks Corey, works just fine :)
     
    SW Monkey, Jun 16, 2004
    #9
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.