Using .sendcommand more than once

Discussion in 'AutoCAD' started by Eugene, Jun 22, 2004.

  1. Eugene

    Eugene Guest

    I have tried to figure this out for most of the day. I am wanting to place
    mtext through VBA;
    ThisDrawing.SendCommand ("(command ""_-vbarun"" ""mtext"")" & vbCr)

    Sub Mtext()
    'start mtext command
    ThisDrawing.SendCommand "MTEXT" & vbCr
    End Sub

    Now I want to change the lineweight of the placed text. I figured I could
    just use;
    .sendcommand "change" & vbCr "properties" & vbCr "previous"......

    Well, that wont work because the two .sendcommands run into eachother. The
    change command doesnt wait until the users places text.

    I've never created a selection set and I havent been able to figure out how
    to create a seletion set of the "previous" object, which would be the placed
    text. Even if I could, I dont know if it would work do to the .sendcommand
    always running last. I tried to break out two subs for the two .sendcommands
    but that still didnt work. I am hoping to do this very simple task w/o
    adding third party applications to register on fifty different workstations.
    Maybe the awnser is to not use .sendcommand to place the mtext but rather go
    the long and hard way? It is just so easy and tempting to use .sendcommand
    if it works. I dont know.... but I'm sure you will, please advise.

    Thanks,
    Eugene
     
    Eugene, Jun 22, 2004
    #1
  2. Why aren't you placing the MText object using the AddMText method? Then you
    could simply use the object itself.

    Sub Test()
    Dim pt0(0 To 2) As Double
    Dim myText As AcadMText
    Set myText = ThisDrawing.ModelSpace.AddMText(pt0, 3, "Is there anybody out
    there?")
    AcadApplication.ZoomExtents
    myText.Highlight True
    End Sub


    --
    R. Robert Bell


    I have tried to figure this out for most of the day. I am wanting to place
    mtext through VBA;
    ThisDrawing.SendCommand ("(command ""_-vbarun"" ""mtext"")" & vbCr)

    Sub Mtext()
    'start mtext command
    ThisDrawing.SendCommand "MTEXT" & vbCr
    End Sub

    Now I want to change the lineweight of the placed text. I figured I could
    just use;
    .sendcommand "change" & vbCr "properties" & vbCr "previous"......

    Well, that wont work because the two .sendcommands run into eachother. The
    change command doesnt wait until the users places text.

    I've never created a selection set and I havent been able to figure out how
    to create a seletion set of the "previous" object, which would be the placed
    text. Even if I could, I dont know if it would work do to the .sendcommand
    always running last. I tried to break out two subs for the two .sendcommands
    but that still didnt work. I am hoping to do this very simple task w/o
    adding third party applications to register on fifty different workstations.
    Maybe the awnser is to not use .sendcommand to place the mtext but rather go
    the long and hard way? It is just so easy and tempting to use .sendcommand
    if it works. I dont know.... but I'm sure you will, please advise.

    Thanks,
    Eugene
     
    R. Robert Bell, Jun 22, 2004
    #2
  3. Eugene

    Eugene Guest

    I've thought of that but it just seemed to be more work than it was worth,
    that is before I was doing anything else but placing mtext. That very well
    may be the answer now that I am going off and changing the properties after
    the text is placed. I would still perfer to use the send command for
    simplicity and user interaction if possible. Any thoughts on how to make my
    current situation work using .sendcommand?

    Thanks,
    Eugene
     
    Eugene, Jun 22, 2004
    #3
  4. Eugene

    wivory Guest

    Robert is right Eugene. I'm afraid you're looking at this the wrong way. The idea of writing a program in VBA is to use the Object Model to give you control over the environment and the objects within it. SendCommand is a hack that sometimes has to be used because Autodesk hasn't provided a complete Object Model.

    That said, it is possible to get your mtext item if you have created it using SendCommand by doing something like the following immediately after it is created:
    [pre]
    Set MyText = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
    [/pre]
    Let me reiterate though, this is a bad way to do it when you have VBA Method already provided for you.

    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Jun 22, 2004
    #4
  5. Hi,

    I've heard rumours that sendcommand can be used sequentially in R2005, but
    have not tested it.

    In the meantime take Robert's advice. You will end up with a far better
    program.

    --

    Regards


    Laurie Comerford
    www.cadapps.com.au

    --

    Regards


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jun 22, 2004
    #5
  6. There was a patch for R15.0 SendCommand which fixes it's asynchronous
    properties. I guess.
     
    Maksim Sestic, Jun 22, 2004
    #6
  7. Eugene

    Eugene Guest

    All,
    Thanks for the input. I'll take your advise and do it right, w/o using
    ..sendcommand. Please check back, I may be looking for help. : )
    Best Regards,
    Eugene
     
    Eugene, Jun 22, 2004
    #7
  8. Eugene

    Eugene Guest

    Ok, First question....

    Why does the carrage return not work with the code below? The mtext value is
    based on user input through a textbox.



    Public sMtxt As AcadMText
    Option Explicit

    Private Sub cbCancel_Click()
    'clear the current value
    tbMtxt.Value = ""
    Me.hide

    Private Sub cbOK_Click()
    'place mtext
    Set sMtxt = ThisDrawing.ModelSpace.AddMText(pt1, 0, tbMtxt.Value)
    'clear the current value
    tbMtxt.Value = ""
    Me.hide
    End Sub

    Private Sub UserForm_Initialize()
    Dim Pnt1 As Variant
    Dim Pnt2 As Variant

    Pnt1 = ThisDrawing.Utility.GetPoint(, "Specify first corner: ")
    End Sub

    Thanks in advance!
    Eugene
     
    Eugene, Jun 22, 2004
    #8
  9. Eugene

    Eugene Guest

    I guess I should have told you in advance that I have already set

    multiLine = true
    and
    EnterKeyBehavior = true

    ACAD2ki
    WinXP

    Thanks!
     
    Eugene, Jun 22, 2004
    #9
  10. Eugene

    Eugene Guest

    Thanks Robert,
    The carrage return isnt working using your sample code either? Does it work
    when you run it?
     
    Eugene, Jun 22, 2004
    #10
  11. Note that I am using A2k5, however.
     
    R. Robert Bell, Jun 22, 2004
    #11
  12. Eugene

    Eugene Guest

    Hummm....Can you think of any reason why your code doesnt work for me? Are
    you using ACAD2000i, could that be the problem?
     
    Eugene, Jun 22, 2004
    #12
  13. Eugene

    Eugene Guest

    I tested your code on a 2002 machine...still one line of text?

    Thanks,
    Eugene
     
    Eugene, Jun 22, 2004
    #13
  14. Eugene

    Ed Jobe Guest

    Wayne suggested just the other day, to use "\P" control char instead of a carriage return.

    --
     
    Ed Jobe, Jun 22, 2004
    #14
  15. (shrug) Works on A2k5.

    Give this procedure a try:

    Private Sub CommandButton1_Click()
    Me.Hide
    Dim pt1 As Variant
    pt1 = ThisDrawing.Utility.GetPoint(, "Specify first corner: ")
    Dim theText As String
    theText = Replace(TextBox1.Text, vbCrLf, "\P")
    Dim myText As AcadMText
    Set myText = ThisDrawing.ModelSpace.AddMText(pt1, 0, theText)
    Unload Me
    End Sub



    --
    R. Robert Bell


    I tested your code on a 2002 machine...still one line of text?

    Thanks,
    Eugene
     
    R. Robert Bell, Jun 22, 2004
    #15
  16. Eugene

    Eugene Guest

    Ed,
    The mtext value isnt preset, while this is built for enduser input. That
    said, I cant see a way to implement "\P" without asking the user to do so
    inplace
    of a carriage return, which of course wouldnt fly. If you have acad 2000i or
    2002 can you test Roberts code to see if it's a version issue. Looking at my
    code do you see any reason why it shouldnt work?
    Thanks!


    Wayne suggested just the other day, to use "\P" control char instead of a
    carriage return.

    --
     
    Eugene, Jun 22, 2004
    #16
  17. Eugene

    Eugene Guest

    Robert,
    Way to go! That worked great. I cant believe I didnt think of replacing the
    carriage return. I guess that happens when your totally grinding and not
    looking at it form the outside in.
    Ed....If that was the direction you were going... sorry for not catching on.

    Stay tuned......
    Thanks ALOT
     
    Eugene, Jun 22, 2004
    #17
  18. Happy to help.

    --
    R. Robert Bell


    Robert,
    Way to go! That worked great. I cant believe I didnt think of replacing the
    carriage return. I guess that happens when your totally grinding and not
    looking at it form the outside in.
    Ed....If that was the direction you were going... sorry for not catching on.

    Stay tuned......
    Thanks ALOT
     
    R. Robert Bell, Jun 22, 2004
    #18
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.