Tyke 发表于 2022-7-6 11:51:46

VBA - SendCommand with PEDIT

Hi,
 
I have a form with several buttons on it and when the first button is clicked a sub routine is called in which I use the SendCommand with pedit to change all objects on a specified layer to polylines and join them into longer polylines. If I close the form from at this point, it all works fine, but if instead of closing the form I then click another button on the form the actions in the newly called sub are exceuted ok but when I now close the form the polylines have not been created. (The second sub just draws a few objects, 3 lines and a circle)
 
Also when I do this sequence of events the second button has to be clicked three times before it draws the objects. But if I reverse the order of clicking the buttons, the button for drawing the objects needs just one click to draw the objects and the polylines are created ok.
 
The user will decide if either of the buttons will be clicked at all and there is no logical connection between the operations. So I can't disable one of the buttons until the other has been clicked.
 
It appears to me that there is a connection with sending the pedit command and closing the form before the polylines are created, but I don't know what. You can see the polylines being created and smoothed after the form closes. I've tried updating the active document and sending a regen command directly after sending the pedit command, but neither make any difference.
 
Anybody got any ideas what I'm doing wrong or what I've not done.
 
Ben

Tyke 发表于 2022-7-6 12:04:05

Got it sorted with the help of CmdrDuh in The Swamp.
 
If anyones interested, you need to hide the form before calling the sub with the SendCommand for PEDIT and after the sub has completed show the form again.
And then alls dunky dory ;-))

todouble22 发表于 2022-7-6 12:24:49

can you post the link that you went to over at the swamp and also if you have any good references for vb knowledge i'd be interested. i'm taking a class on that and c++ right now and want to incorporate some cad stuff to it

ollie 发表于 2022-7-6 12:38:20

Hi
 
The Activedocument.utility.sendCommand runs asynchronously from the vba routine,function etc. that calls it Meaning that it won'trun the parsed command until the vba sub has finished (in this case when the form is closed)
 
It sounds like one of the problems you are having is not passing the return character after each lineFor example Pedit may be used in a manner similar to this
 

//I have used !sset as the selection set. Not sure what method you will be using//Return character in unicode is\r (equivalent to enter or returnDim Cmd as StringCmd = "pedit\rm\r!sset\rjoin\r\r\r"pseudopedit return//start peditmultiple (m) return   //multiple selectionselection set, method return   //set selectionjoin (j) return             //join selected objectreturn   //default joinreturn// end joinreturn//end pedit
 
As for running the function using this method you will need to exit the sub by closing the form or ending the function. My best bet is for this task would be to extend the 'Cmd' string to recall the open user form function. For example
 

//Run function that opens the user form from command line or wherever vbarunopenUserForm//Append above code...Cmd = Cmd +"vbarun\ropenUserForm\r"Not the best solution but it will work.
 
Hope that helps,
Ollie

Tyke 发表于 2022-7-6 12:41:19

Todd - here's the link for the topic at TheSwamp   http://www.theswamp.org/index.php?topic=31627.0
 
A good reference for VB.NET is Jerry Winters book VB.NET Programming for AutoCAD Customization - Level 1.For VBA Joe Sutphin's book is very good, but VBA is on its way out.
 
You got it in a nutshell Ollie.Thanks.
 
Tyke

Tyke 发表于 2022-7-6 13:01:19

Todd - Jerry Winters has just released a new version of his book 'VB.NET for AutoCAD 2010'
页: [1]
查看完整版本: VBA - SendCommand with PEDIT