一个结合Lisp的拖动例子
Lisp函数:,先导入一下(defun Drag( pBlock / ppnt ed ped)(defun GetPoint( / a pnt )
(setq a (grread t))
(setq pnt (list 0 0 1))
(if (= 3 (car a)) (setq pnt (list 0 0 -1)))
(if (= 5 (car a)) (setq pnt (cadr a)))
pnt
)
(while (not (= (caddr (setq ppnt (GetPoint))) -1))
(setq ed (entget (handent pBlock)))
(setq ped (list 10 (car ppnt) (cadr ppnt) (caddr ppnt)))
(setq ed (subst ped (assoc 10 ed) ed))
(entmod ed)
)
)测试(由于拖动在Lisp中做好了,不需频繁调用Vlax类,应该不会使AutoCad崩溃):Sub Test()
Dim obj As VLAX
Dim c(2) As Double
Dim pObj As AcadBlockReference
Set obj = New VLAX
Set pObj = ThisDrawing.ModelSpace.InsertBlock(c, "123", 1, 1, 1, 0)
a = "(drag " & Chr(34) & pObj.Handle & Chr(34) & ")"
obj.EvalLispExpression (a)
Set obj = Nothing
End Sub
看不懂啊~~~
是不是插入图块时能显示图块? 差不多是这个意思
思路是在VBA里插入一个块
再通过Vlax类调用Lisp函数Drag做拖动
模拟Move命令的操作
(当然没有Move做的好,因为Lisp毕竟不是我的强项,只懂点皮毛) 改良版(不需导入Lisp函数)Public Sub BlockInsert(Name As String)
Dim pLisp As String
Dim obj As VLAX
Dim pnt(2) As Double
Set obj = New VLAX
Set pObj = ThisDrawing.ModelSpace.InsertBlock(pnt, Name, 1, 1, 1, 0)
obj.EvalLispExpression "(setq ed (entget (handent " & ToStr(pObj.Handle) & ")))"
pLisp = "(while (not (= (caddr " & _
"(setq pTime (grread t) " & _
"pSt (car pTime) " & _
"pnt (cond ((= pSt 3) (List 0 0 -1)) ((= pSt 5) (cadr pTime)) (t (List 0 0 1))))) -1)) " & _
"(setq ed (subst (cons 10 pnt) (assoc 10 ed) ed)) " & _
"(entmod ed) " & _
") "
obj.EvalLispExpression pLisp
Set obj = Nothing
End SubPublic function ToStr(ByVal str) As String
ToStr = Chr(34) & str & Chr(34)
End Function
Sub test()
BlockInsert "123"
End Sub
2002怎么没有VLAX类? vlax 如何引用?
"Dim obj As VLAX" Dim obj As VLAX<BR>Set obj = New VLAX<BR> 执行到"Dim obj As VLAX"是显示用户类型未定义。也就是说你的代码不能直接运行(cad2000)。请指教,谢谢。 VLAX类未导入 究竟怎么导入?我对vlax一窍不通。
要想运行你的代码,还要设置些什么?谢谢
页:
[1]
2