CAD LISP 施工、规划设计点位的编号注记

4 篇文章 0 订阅
2 篇文章 0 订阅

实现CAD快速注记编号,可以通过lisp语言实现快速注记,注记样式中:编号样式,引线,边框,文字样式均可以自己设置。

;参数初始化
(defun chushihua()
  ;(setvar "cmdecho" 0)
  (setq bhlx 0)
  (write-line "编号类型:0")
  (setq bh0 0)
  (write-line "编号初值:1")
  (setq bh1 64)
  (setq bh2 0)
  (setq bh3 64)
  (setq yx "Y")
  (write-line "引线:Y")
  (setq bklx "Y")
  (write-line "边框:Y")
  (setq r 2.5)
  (setq zidong_r t)
  (write-line "边框圆半径:自动")
  (setq th 3.5)
  (write-line "文字高度:3.5")
  (setq ta 0)
  (write-line "文字旋转角度:0")
  (setq jl 1)
  (write-line "编号到引线距离:1")
  (setq jiantou 2.5)
  (write-line "箭头大小:2.5")
  (setq chang 5)
  (setq zidong_chang t)
  (write-line "水平段引线长度:自动")
  (setq qianzhui2 "")
  (write-line "自然数前缀:无")
  (setq houzhui2 "")
  (write-line "自然数后缀:无")
  (setq qianzhui3 "")
  (write-line "字母前缀:无")
  (setq houzhui3 "")
  (write-line "字母后缀:无")
  (setq pianyi 7)
  (write-line "边框自动处理时,文字到边框的偏移系数:7") 
)
(chushihua)

;主函数*********************************************************************

(defun c:BHZJ(/ o ob)
  (defun er(str)
    (setvar "osmode" dx)    
    (princ "\n编号注记已取消")    
  )
  (setq erod *error* *error* er)
  (if (= yx "N")
    (progn
      (initget "C Y K W H T")
      (setq ob (getpoint "\n指定编号位置[编号初值(C)/引线(Y)/边框(K)/文字(W)/还原为默认设置(H)/退出(T)]:<编号设置样式/默认设置>"))
      (if (or (= ob "C") (= ob "Y") (= ob "T") (= ob "K") (= ob "W") (= ob "H") (= ob nil))
	(progn
	  (if (= ob "C") (chuzhi))           
          (if (= ob "Y") (yinxian))
	  (if (= ob "K") (bkshezhi))
	  (if (= ob "W") (wenzi))
	  (if (= ob "H") (chushihua))
	  (if (= ob nil) (gaodu0))


	  (if (= ob "T") (exit))
	)
        (progn
	  (huitu o ob)
	)
      )
    )
    (progn
      (initget "C Y K W H T")
      (setq o (getpoint "\n指定标注位置[编号初值(C)/引线(Y)/边框(K)/文字(W)/还原为默认设置(H)/退出(T)]:<编号之前请先将当前文字样式的文字高度项设为0>"))
      (if (or (= o "C") (= o "Y") (= o "T") (= o "K") (= o "W") (= o "H") (= o nil))
	(progn
	  (if (= o "C") (chuzhi))           
          (if (= o "Y") (yinxian))
	  (if (= o "K") (bkshezhi))
	  (if (= o "W") (wenzi))
	  (if (= o "H") (chushihua))
	  (if (= o nil) (gaodu0))


	  (if (= o "T") (exit))
	)
        (progn
          (initget 1)
	  (setq ob (getpoint o "\n指定编号位置:"))	  
	  (huitu o ob)
	)
      )
    )    
  )

)


;绘制过程*********************************************************************************

(defun huitu(o ob / dian1 dian2 dianx diany jiantou0 chang0)
  (graphscr)

  (setq jiantou0 jiantou)
  (command "text" '(0 0) th ta "编号注记" "erase" (entlast) "")
  

  
  
  ;编号升序
  ;0 (1 2 3...) 1 (a b c.../A B C...) 2 (a1 a2.../B1 B2...) 3 (aa ab ac.../Ma Mb Mc...)
  (if (= bhlx 0)
    (progn
      (setq bh0 (+ bh0 1))
      (setq bh (itoa bh0))
    )
  )
  (if (= bhlx 1)
    (progn
      (setq bh1 (+ 1 bh1))
      (if (> bh1 122) (setq bh1 97))
      (if (and (> bh1 90) (< bh1 97)) (setq bh1 65))
      (if (< bh1 65) (setq bh1 65))
      (if (and (< bh1 97) (> bh1 90)) (setq bh1 97))
      (setq bh (chr bh1))
    )
  )

  (if (= bhlx 2)
    (setq bh (strcat qianzhui2 (itoa (setq  bh2 (+ 1 bh2))) houzhui2))
  )

  (if (= bhlx 3)
    (progn
      (setq bh3 (+ 1 bh3))
      (if (> bh3 122) (setq bh3 97))
      (if (and (> bh3 90) (< bh3 97)) (setq bh3 65))
      (if (< bh3 65) (setq bh3 65))
      (if (and (< bh3 97) (> bh3 90)) (setq bh3 97))
      (setq bh (strcat qianzhui3 (chr bh3) houzhui3))
    )
  
  )

  (if (= bklx "Y")       ;边框半径是否自动处理及r0值
    (progn
      (if (= zidong_r t)
	(setq r0 (/ (tdaxiao 3) 2))
	(setq r0 r)
      )
    )
    (setq r0 (/ (tdaxiao 2) 2))
  )
  (if (= bklx "J")       ;边框为矩形时r0值
    (if (= zidong_j t)
      (setq r0 (/ (tdaxiao 2) 2))
      (setq r0 (/ jgao 2))
    )
  )
  
  (if (= zidong_chang t) ;引线长度是否自动处理及chang0值
    (progn
      (if (= bklx "Y")
	(setq chang0 (* r0 2))
	(progn
          (if (= bklx "J")
	    (if (= zidong_j t)
	      (setq chang0 (tdaxiao 1))
	      (setq chang0 jkuan)	   
	    )
	    (if (= bklx "W")
	      (setq chang0 (tdaxiao 1))
	    )
	  )
	) 
	
      )
    )
    (setq chang0 chang) 
  )

  ;对象捕捉
  (setq dx (getvar "osmode"))
  (setvar "osmode" 0)  


  
  
  (biankuangy r0 ob bh)
  (if (and (/= yx "N") (/= yx "n"))
    (progn
      (if (>= (car o) (car ob))
        (progn 
          (setq dian1 (list(+ (car ob) (/ chang0 2)) (- (cadr ob) r0 jl)))
          (setq dian2 (list(- (car ob) (/ chang0 2)) (- (cadr ob) r0 jl)))
          (if (> jiantou0 (distance o dian1)) (setq jiantou0 0))
	  (setq dianx (+ (car o) (* (/ jiantou0 (distance o dian1)) (- (car dian1) (car o)))))
	  (setq diany (+ (cadr o) (* (/ jiantou0 (distance o dian1)) (- (cadr dian1) (cadr o)))))
	  (command "pline" o "w" 0 (/ jiantou0 3) (list dianx diany) "w" 0 0 dian1 dian2 "")

	  
        )
	(progn
          (setq dian1 (list(- (car ob) (/ chang0 2)) (- (cadr ob) r0 jl)))
	  (setq dian2 (list(+ (car ob) (/ chang0 2)) (- (cadr ob) r0 jl)))
	  (if (> jiantou0 (distance o dian1)) (setq jiantou0 0))
          (setq dianx (+ (car o) (* (/ jiantou0 (distance o dian1)) (- (car dian1) (car o)))))
	  (setq diany (+ (cadr o) (* (/ jiantou0 (distance o dian1)) (- (cadr dian1) (cadr o)))))
	  (command "pline" o "w" 0 (/ jiantou0 3) (list dianx diany) "w" 0 0 dian1 dian2 "")

	  
        )
      )
    )
  )
  ;对象捕捉
  (setvar "osmode" dx)
  (setq *error* erod erod nil)

(eval bh)
  
)



;参数设置********************************************************************************

;初值设置
(defun chuzhi(/ qianzhui20 houzhui20 qianzhui30 houzhui30)
      
      
      (initget 1 "0 1 2 3")
      (setq bhlx (atoi (getkword "选择一种编号类型:\n<0>  自然数序列(1 2 3...)  <1>  字母序列(a b c.../A B C...)  <2>  带前/后缀自然数序列(a1 a2.../B1 B2.../(1)...)  <3>  带前/后缀字母序列(aa ab ac.../Ma Mb Mc.../(a)...)  选择其中一种0/1/2/3:")))
      (if (= bhlx 0)
        (progn
          (setq bh0 (getint "\n输入起始数值:<1>"))
	  (if (= bh0 nil) (setq bh0 1))
	  (setq bh0 (1- bh0))
	)
      )
      (if (= bhlx 1)
        (progn	  
	  (setq bh1 (1- (ascii (getstring "\n输入起始字母:<A>"))))
	)
      )
      (if (= bhlx 2)
        (progn
	  (setq qianzhui20 (getstring (strcat "输入前缀:<" qianzhui2 ">")))
	  (if (/= qianzhui20 "") (setq qianzhui2 qianzhui20))
	  (setq bh2 (getint "\n输入起始数值:<1>"))
	  (if (= bh2 nil) (setq bh2 1))
	  (setq bh2 (1- bh2))
	  (setq houzhui20 (getstring (strcat "输入后缀:<" houzhui2 ">")))
	  (if (/= houzhui20 "") (setq houzhui2 houzhui20))
	)
      )
      (if (= bhlx 3)
        (progn
	  (setq qianzhui30 (getstring (strcat "输入前缀:<" qianzhui3 ">")))
	  (if (/= qianzhui30 "") (setq qianzhui3 qianzhui30))
	  (setq bh3 (1- (ascii (getstring "\n输入起始字母:<A>"))))
	  (setq houzhui30 (getstring (strcat "输入后缀:<" houzhui3 ">")))
	  (if (/= houzhui30 "") (setq houzhui3 houzhui30))
	)
      )

    

  (c:sb)
)

;引线设置
(defun yinxian(/ yx0 yxf jl0 chang0 jiantou0)
  (initget "Y N")
  (if (= yx "Y") (setq yxf "N") (setq yxf "Y"))
  (setq yx0 (getkword (strcat "\n" "编号是否带引线?<Y>/<N>:<" yxf ">")))
  (if (= yx0 nil) (setq yx yxf) (setq yx yx0))
  (if (= yx "Y")
    (progn
      (setq jl0 (getdist (strcat "输入编号到引线的距离:<" (rtos jl) ">")))
      (if (/= jl0 nil) (setq jl jl0))
      (setq chang0 (getdist "输入水平段引线的长度:<自动>"))
      (if (/= chang0 nil) (setq chang chang0 zidong_chang nil) (setq zidong_chang t))
      (setq jiantou0 (getdist (strcat "输入箭头大小:<" (rtos jiantou) ">")))
      (if (/= jiantou0 nil) (setq jiantou jiantou0))


      
    )
  )
  (c:sb)
)

;边框设置
(defun bkshezhi(/ r0)
  (initget 1 "Y W J")
  (setq bklx (getkword "\n选择边框类型[圆(Y)/矩形(J)/无(W)]:"))
  
  (if (= bklx "Y")
    (progn
      
      (setq r0 (getdist (strcat "输入圆半径:<" "自动" ">")))
      (if (/= r0 nil) (setq r r0 zidong_r nil) (setq zidong_r t))
    )
  )
  (if (= bklx "J")
    (progn
      (setq jkuan (getdist "\n输入矩形宽:<自动>"))
      (if (= jkuan nil)
	(setq zidong_j t)
	(progn
	  (setq zidong_j nil)
	  (setq jgao (getdist "\n输入矩形高度:"))
        ) 
      )
    )
  )
  

  
  
  
  

(c:sb)
)
;文字设置
(defun wenzi(/ th0 ta0)
(setq th0 (getdist (strcat "输入文字高度:<" (rtos th) ">")))
  (if (/= th0 nil)
    (progn
      (setq th th0)
      
    )
    
  )
      
  
  (setq ta0 (getangle (strcat "输入文字角度:<" (rtos ta) ">")))
  (if (/= ta0 nil)
    (progn
      (setq ta ta0)
      (setq ta (* (/ ta pi) 180))
    )
  )

(c:sb)
)  

;绘边框  
(defun biankuangy(banjing yuanxin bianhao)
  (if (= bklx "Y")
    (command "circle" yuanxin banjing)
  )
  (if (= bklx "J")
    (progn
      (if (= zidong_j t)
	(setq jkuan0 (tdaxiao 1) jgao0 (tdaxiao 2))
	(setq jkuan0 jkuan jgao0 jgao)
      )
      (command "pline")
      (command (list (- (car yuanxin) (/ jkuan0 2)) (- (cadr yuanxin) (/ jgao0 2))))
      (command "w" 0 0)
      (command (list (+ (car yuanxin) (/ jkuan0 2)) (- (cadr yuanxin) (/ jgao0 2))))
      (command (list (+ (car yuanxin) (/ jkuan0 2)) (+ (cadr yuanxin) (/ jgao0 2))))
      (command (list (- (car yuanxin) (/ jkuan0 2)) (+ (cadr yuanxin) (/ jgao0 2))))
      (command "c")
    )
  )



  
  (command "text" "J" "MC" yuanxin th ta bianhao)

)  
;将当前文字样式的文字高度项设置为0
(defun gaodu0() 
  (command "style" "" "" 0 "" "" "" "" "")
  (c:sb)
)


;编号文字宽与高
(defun tdaxiao(x / a b c)  ;x=t则b=宽.x=nil则b=高
  (setq a (textbox (list (cons 1 bh))))
  (setq c (/ (- (cadar a) (cadadr a)) pianyi))
  (if (= x 1)
    (setq b (- (caadr a) (caar a) c))
    (if (= x 2)
      (setq b (- (cadadr a) (cadar a) c))
      (setq b (- (distance (car a) (cadr a)) c))
    )
  )
  (eval b)
)
  

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: VisualLISP是一种面向对象的编程语言,用于编写AutoCAD的自定义程序。它是AutoLISP的一个扩展,包含了AutoLISP的全部功能,并添加了许多额外的功能和方法,以实现更高级的程序设计和图形处理。 使用VisualLISP编程,可以实现对AutoCAD软件的各种功能进行自定义扩展,例如创建新的命令、绘制特定的图形、修改现有的对象等。通过使用VisualLISP,可以提高效率,并且可以根据自己的需求自由定制AutoCAD软件。 在AutoCAD 2010中,使用VisualLISP进行程序设计可以实现更多的功能和操作。通过VisualLISP,可以编写更复杂的命令脚本,如批处理、自动化绘图等。此外,VisualLISP还提供了调试工具和错误处理机制,可以更轻松地调试和测试程序,提高开发效率。 要使用VisualLISP进行编程,首先需要了解AutoLISP的基本语法和AutoCAD软件的对象模型。然后,可以使用VisualLISP编辑器创建新的LSP文件,并在其中编写程序代码。编写完成后,将LSP文件加载到AutoCAD中,即可使用新的命令或功能。 总而言之,VisualLISP是一种用于AutoCAD软件的编程语言,它提供了更多的功能和方法,可以实现更高级的程序设计和图形处理。通过使用VisualLISP,可以定制AutoCAD软件,提高工作效率,并实现更多的自动化操作。 ### 回答2: Visuallisp程序设计是一种用于AutoCAD 2010的编程语言。它是一种基于lisp的语言,可以用于开发自定义的AutoCAD功能。 使用Visuallisp编程,可以通过自定义命令、工具栏和菜单来扩展AutoCAD的功能。Visuallisp语言能够访问AutoCAD对象模型,包括图形、图层、块等,可以实现自动化的CAD操作。 Visuallisp程序设计具有以下特点: 1. 易学易用:Visuallisp语法简单,类似于其他编程语言,如C语言和lisp。初学者可以很快上手,掌握基本的编程技能。 2. 强大的功能:Visuallisp可以访问AutoCAD的全套功能,包括图形绘制、图层管理、实体编辑、块操作等。可以编写复杂的CAD程序,满足各种需求。 3. 可扩展性:Visuallisp程序可以通过自定义函数和宏来扩展AutoCAD的功能。可以根据需求添加新的命令和功能,提高工作效率。 4. 与AutoCAD的集成:Visuallisp程序可以无缝集成到AutoCAD中,通过AutoCAD的编程接口来访问和操作CAD对象。可以直接在AutoCAD的环境中调试和运行Visuallisp程序。 总之,Visuallisp程序设计是一种强大而灵活的开发工具,可以帮助用户定制和扩展AutoCAD的功能,提高CAD设计和绘图的效率。无论是初学者还是有经验的AutoCAD用户,都可以通过学习和运用Visuallisp编程来提升工作能力。 ### 回答3: VisualLISP是一种用于Autodesk AutoCAD 2010的程序设计语言。它是一种基于LISP(List Processing)编程语言的扩展,用于自动化和定制化AutoCAD软件。通过使用VisualLISP,用户可以使用LISP编程语言创建自己的工具和命令,以增强其CAD设计和绘图的功能。 通过VisualLISP,用户可以利用LISP编程语言的强大功能来编写程序,实现一些常规操作的自动化,提高工作效率。此外,由于VisualLISP是内置在AutoCAD中的,因此它可以直接访问并操作AutoCAD的各种功能和对象。用户可以通过编写LISP脚本来创建自定义命令,以实现自己独特的CAD设计需求。通过VisualLISP,用户可以使用一些预定义的函数和命令,来简化编程过程,减少代码量,并提高代码的可维护性。 在AutoCAD 2010中,VisualLISP为用户提供了一些新的功能和改进。例如,新的运行时编辑器使得用户可以在AutoCAD应用程序中编辑和调试LISP代码,以更快地开发和测试新的程序。另外,VisualLISP还提供了一些新的函数和命令,以增强用户对AutoCAD对象的访问和操作能力。 总之,VisualLISP是一个强大的程序设计工具,可以帮助AutoCAD用户实现定制化和自动化的CAD设计和绘图任务。通过编写LISP脚本,用户可以创建自己的工具和命令,提高工作效率,并满足其个性化的设计需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

板混少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值