Running action recorded command through VBA

Running action recorded command through VBA

Anonymous
Not applicable
1,030 Views
1 Reply
Message 1 of 2

Running action recorded command through VBA

Anonymous
Not applicable

So I have multiple rectangles in a single dwg.  I want to copy one rectangle based on user input.  For example I prompt the user for width and length and it copies that specific rectangle.  I know how to get the user input and i can get the rectangle copied.  My problem is the command I use to do it.  I recorded an action recording in autocad called "1836CPY" which copies the 18" x 36" rectangle in my dwg.  I call it in my vba code as you see below:

 

ThisDrawing.SendCommand "COPY1836" & vbCr

 

It works flawlessly, the only problem is after I run this code once that line seems to make it to where the vba never stops running.  I can't hit stop and I can't edit my code.  I can't even hit ctrl + break to stop the code.  the vba editor is just frozen, like it is running indefinitely.  I know sendcommand is not ideal but it works very well with copying what rectangle I need.  Please help! 

0 Likes
1,031 Views
1 Reply
Reply (1)
Message 2 of 2

grobnik
Collaborator
Collaborator

Hi @Anonymous,

I'm still working on code I posted some days ago, in reply to your post with the same issue more or less, but I guess you already have a code.

So, in order to help you with your code COPY1836 or similar without seeing it seems a little hard to help you. 

I'm suggesting to share your code and a sample dwg too, if you need more help from others.

 

However there should be a function for copying objects but I'm finding some issue and I don't know why, this is the reason because I did not reply yet to your post.

 

As explained before you have the collection of objects inside your rectangle (polyline) (ssetObj), copied in an array sourceEnts, create a new document Set DOC1 = Documents.Add and next step should be copy the array contents into new document retObjects = DOC0.CopyObjects(sourceEnts, Doc1MSpace), but nothing happen in my case, array contents it's filled, but retObject it's empty and nothing will be transferred to new doc.

In any case now I understand you want to copy only rectangle shape and not eventually contents.

Dim sourceEnts()

ReDim sourceEnts(ssetObj.Count - 1)
For i = 0 To ssetObj.Count - 1
    Set sourceEnts(i) = ssetObj(i)
Next

'' you must cache the source document here, because
'' documents.add will change our thisdrawing context

Dim DOC0 As AcadDocument
Set DOC0 = ThisDrawing.Application.ActiveDocument
Dim Doc1MSpace As AcadModelSpace
Dim DOC1 As AcadDocument
Set DOC1 = Documents.Add
Set Doc1MSpace = DOC1.ModelSpace

'' copy the source entities into destination modelspace
'destEnts = objSource.CopyObjects(sourceEnts, objDest.ModelSpace)
retObjects = DOC0.CopyObjects(sourceEnts, Doc1MSpace)

Done:

'' clean up selection set
ssetObj.Delete