乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 95|回复: 5

[编程交流] VBA - SendCommand with PEDIT

[复制链接]

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 11:51:46 | 显示全部楼层 |阅读模式
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
回复

使用道具 举报

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 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 ;-))
回复

使用道具 举报

8

主题

80

帖子

72

银币

初来乍到

Rank: 1

铜币
40
发表于 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
回复

使用道具 举报

37

主题

125

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
190
发表于 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't  run 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 line  For example Pedit may be used in a manner similar to this
 
  1. //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
 
  1. //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
回复

使用道具 举报

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 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
回复

使用道具 举报

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 13:01:19 | 显示全部楼层
Todd - Jerry Winters has just released a new version of his book 'VB.NET for AutoCAD 2010'
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 10:04 , Processed in 0.913457 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表