Stop "sendcommand" to press Enter

Stop "sendcommand" to press Enter

abbas.baghernezhad
Enthusiast Enthusiast
1,876 Views
15 Replies
Message 1 of 16

Stop "sendcommand" to press Enter

abbas.baghernezhad
Enthusiast
Enthusiast

In this macro I want to add Diameter Dimension at every circle in the drawing. In each circle it waits for user to press enter at the end and it can't be solved with "vbCr"!

How can I stop it to wait for enter?

 

Sub CM()
Dim ent As AcadEntity
Dim FullCircle As AcadCircle
Dim CenterPx, CenterPy As String
Dim DimPx, DimPy As String

  For Each ent In ThisDrawing.ModelSpace
      If TypeOf ent Is AcadCircle Then
      Set FullCircle = ent 

      ThisDrawing.Application.Update
      ZoomAll
      DimPx = CStr(FullCircle.Center(0) + FullCircle.Radius)
      DimPy = CStr(FullCircle.Center(1) + FullCircle.Radius)
      ThisDrawing.SendCommand "_AMPOWERDIM_DIA" & vbCr & CenterPx & "," & CenterPy & vbCr & DimPx & "," & DimPy & vbCr & vbCr

      End If
    Next
    
  End Sub

 

0 Likes
1,877 Views
15 Replies
Replies (15)
Message 2 of 16

Ed__Jobe
Mentor
Mentor

I didn't test your code, but Cr stands for Carriage Return. It just makes the cursor move to position 1 on the current line. The {Enter} key does a Line Feed, moving the cursor to the next line. So you either need to use vbCrLf or vbLf.

 

Also, when you Dim variables on the same line, you have to specify the type for each variable. If you don't, the Variant data type is used. In your code above DimPx is a Variant and DimPy is a string. For both of them to be a string you would use:

Dim DimPx As String, Dim DimPy As String

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 16

abbas.baghernezhad
Enthusiast
Enthusiast

Thank You.

I learned new things.

But it didn't work. I guess it is because it needs to press enter on cursor , not on the command line. So How can I press enter?

0 Likes
Message 4 of 16

Ed__Jobe
Mentor
Mentor

It looks like the AMPOWER command you are trying to use belongs to acad mech, I assume. I don't have that installed, so I can't help you further.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 16

abbas.baghernezhad
Enthusiast
Enthusiast

we can use "DIMDIAMETER" instead. There is No difference!

0 Likes
Message 6 of 16

Ed__Jobe
Mentor
Mentor

I don't see in your code where you set CenterPx and CenterPy. Therefore, you are probably getting an "invalid point" error and the second point is being accepted as the first point. So it's still waiting for you to enter a point.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 16

abbas.baghernezhad
Enthusiast
Enthusiast

here is the Whole code, It still has the problem.


 

Sub CM()
Dim ent As AcadEntity
Dim FullCircle As AcadCircle
Dim CenterPx, CenterPy As String
Dim DimPx, DimPy As String

  For Each ent In ThisDrawing.ModelSpace
      If TypeOf ent Is AcadCircle Then
      Set FullCircle = ent
  
      CenterPx = CStr(FullCircle.Center(0))
      CenterPy = CStr(FullCircle.Center(1) + FullCircle.Radius)
      ThisDrawing.SendCommand "_CM" & vbCr & CenterPx & "," & CenterPy & vbCr & vbCr
      ThisDrawing.Application.Update
      ZoomAll
      DimPx = CStr(FullCircle.Center(0) + FullCircle.Radius)
      DimPy = CStr(FullCircle.Center(1) + FullCircle.Radius)
      ThisDrawing.SendCommand "_AMPOWERDIM_DIA" & vbCr & CenterPx & "," & CenterPy & vbCr & DimPx & "," & DimPy & vbCr & vbCr

      End If
    Next
    
  End Sub
​

 


 

0 Likes
Message 8 of 16

baksconstructor
Advocate
Advocate
Sub CM()
Dim ent As AcadEntity
Dim FullCircle As AcadCircle
Dim CenterPx, CenterPy As String
Dim DimPx, DimPy As String

  For Each ent In ThisDrawing.ModelSpace
      If TypeOf ent Is AcadCircle Then
      Set FullCircle = ent

      ThisDrawing.Application.Update
      ZoomAll
      DimPx = CStr(FullCircle.Center(0) + FullCircle.Radius)
      DimPy = CStr(FullCircle.Center(1) + FullCircle.Radius)
      ThisDrawing.SendCommand "_DIMDIAMETER" & vbCr
ThisDrawing.SendCommand CenterPx & "," & CenterPy & vbCr & DimPx & "," & DimPy & vbCr & vbCr
      End If
    Next
    
  End Sub
0 Likes
Message 9 of 16

Ed__Jobe
Mentor
Mentor

Have you tried setting a breakpoint and debugging? When using SendCommand it is especially important to monitor the command line and sequence of events.

 

Your first use of SendCommand calls _CM. This is the same as your sub's name and also the shortcut for the CENTERMARK command. This use is amibguous. I would rename your sub to remove ambiguity.

 

Although the signature for the DIM statement show the As keyword as optional, note what help says about leaving out the type declaration:

 

If you don't specify a data type or object type, and there is no Deftype statement in the module, the variable is Variant by default.

Therefore, CenterPx and DimPx are variants. Just fyi.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 10 of 16

abbas.baghernezhad
Enthusiast
Enthusiast

Hi.

Splitting sendcommand doesn't help at all.

Thank you.

0 Likes
Message 11 of 16

abbas.baghernezhad
Enthusiast
Enthusiast

Thank You Again.

Yes of course I tried to debug my code.

I edited my code. Changing sub name and correcting varable types...I still need to press enter!

0 Likes
Message 12 of 16

Ed__Jobe
Mentor
Mentor

I was able to do it with DIMDIAMETER command. Show your modified code.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 13 of 16

abbas.baghernezhad
Enthusiast
Enthusiast

Here it is:

Sub CentMark()
Dim ent As AcadEntity
Dim FullCircle As AcadCircle
Dim CenterPx As String, CenterPy As String
Dim DimPx As String, DimPy As String

  For Each ent In ThisDrawing.ModelSpace
      If TypeOf ent Is AcadCircle Then
      Set FullCircle = ent
  
      CenterPx = CStr(FullCircle.Center(0))
      CenterPy = CStr(FullCircle.Center(1) + FullCircle.Radius)
      ThisDrawing.SendCommand "_CM" & vbCr & CenterPx & "," & CenterPy & vbCr & vbCr
      ThisDrawing.Application.Update
      ZoomAll
      DimPx = CStr(FullCircle.Center(0) + FullCircle.Radius)
      DimPy = CStr(FullCircle.Center(1) + FullCircle.Radius)
      ThisDrawing.SendCommand "_AMPOWERDIM_DIA" & vbCr & CenterPx & "," & CenterPy & vbCr & DimPx & "," & DimPy & vbCr & vbCr

      End If
    Next
    
  End Sub
0 Likes
Message 14 of 16

Ed__Jobe
Mentor
Mentor

Two problems.

1. You didn't use a line feed like I suggested. Use vbCrLf instead of vbCr.

2. You didn't check the command line (F2) when debugging, like I suggested. See the command line report below:

 

Command: _CM
CENTERMARK
Select circle or arc to add center mark:
Command: 20.4125331509048,12.0722926214424
Unknown command "4125331509048,12.0722926214424".  Press F1 for help.
Command:
Command:
CENTERMARK
Select circle or arc to add center mark:
Command: DIMDIAMETER
Select arc or circle:
Command: 20.4125331509048,12.0722926214424
Unknown command "4125331509048,12.0722926214424".  Press F1 for help.
Command:
DIMDIAMETER
Select arc or circle: 21.3998900501084,12.0722926214424
Select arc or circle:
Command:
DIMDIAMETER
Select arc or circle:

 

Notice that it keeps prompting to select a circle? You can't do that by entering a center point coordinate. You have to select on screen. I tried a trick I use, but it didn't work. I think the only way is to not use SendCommand and add your own center mark and dims.

 

edit:

Unfortunately, VBA does not have a center mark entity. You would only be able to add the dims. To automate the center mark, you would need to use C#. Lisp could do it, but it's more complicated. To lisp, a center mark is an anonymous block.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 15 of 16

abbas.baghernezhad
Enthusiast
Enthusiast

Thank You Again.

I used your adviced and as you said it may not have a straight solution. But the problem was not with CM. It waits for my enter for dimension command before going to next circle.

0 Likes
Message 16 of 16

Ed__Jobe
Mentor
Mentor

Yes, once the command prompts you to select an entity, you must select it with the mouse. Usually you can use the lisp (handent) function to pass the command an ename, but these two commands aren't having it.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature