乐筑天下

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

[编程交流] 在的端点插入块

[复制链接]

46

主题

161

帖子

104

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
242
发表于 2022-7-5 15:24:12 | 显示全部楼层 |阅读模式
我想在曲线的末端插入动态块,并将其角度参数拟合到曲线。
 
如何计算最后一段为圆弧的样条线或样条线的该角度。
请参阅附件。
 
下面你可以找到我的第一个想法,但这只适用于wcs。如果它也能在任何ucs中工作,那就太好了。
 
  1. (defun c:gtas ( /
  2.                  LM:SelectIf LM:setdynpropvalue cd:BLK_InsertBlock
  3.                  _ent _start_param _start_hlp_param _end_param _end_hlp_param
  4.              )
  5. ;;; SUB
  6. (defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred))  
  7.    (while
  8.      (progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg))
  9.        (cond
  10.          ( (= 7 (getvar 'ERRNO))
  11.            (princ "\nMissed, Try again.")
  12.          )
  13.          ( (eq 'STR (type sel))
  14.            nil
  15.          )
  16.          ( (vl-consp sel)
  17.            (if (and pred (not (pred sel)))
  18.              (princ "\nInvalid Object Selected.")
  19.            )
  20.          )
  21.        )
  22.      )
  23.    )
  24.    sel
  25. )
  26. (defun LM:setdynpropvalue ( blk prp val )
  27.      (setq prp (strcase prp))
  28.      (vl-some
  29.         '(lambda ( x )
  30.              (if (= prp (strcase (vla-get-propertyname x)))
  31.                  (progn
  32.                      (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
  33.                      (cond (val) (t))
  34.                  )
  35.              )
  36.          )
  37.          (vlax-invoke blk 'getdynamicblockproperties)
  38.      )
  39. )
  40. (defun cd:BLK_InsertBlock (Pb Name Xyz Rot Sup / zdir xang res)
  41.     (setq   
  42.        zdir (trans '(0 0 1) 1 0 T)
  43.        xang (angle '(0 0 0) (trans (getvar "UCSXDIR") 0 zdir))
  44.     )
  45.     (if
  46.      (not
  47.        (vl-catch-all-error-p
  48.          (setq res
  49.            (vl-catch-all-apply
  50.              (quote vla-InsertBlock)
  51.              (list
  52.                (cd:ACX_ASpace)
  53.                (vlax-3d-point (trans Pb 1 0))
  54.                (if (tblsearch "BLOCK" Name)
  55.                  Name
  56.                  (if Sup
  57.                    (findfile (strcat Name ".dwg"))
  58.                    nil
  59.                  )
  60.                )
  61.                (if (not Xyz) 1.0 (car Xyz))
  62.                (if (not Xyz) 1.0 (cadr Xyz))
  63.                (if (not Xyz) 1.0 (caddr Xyz))
  64.                (if (not Rot) 0.0 (+ Rot xang))
  65.              )
  66.            )
  67.          )
  68.        )
  69.      )
  70.      res
  71.    )
  72. )
  73. ;;; END SUB
  74. (if
  75.    (setq _ent
  76.      (car
  77.        (LM:SelectIf
  78.          "\nSelect curve to add axis symbol"
  79.          (lambda ( x ) (wcmatch (cdr (assoc 0 (entget (car x)))) "*LINE") )
  80.          entsel nil
  81.        )
  82.      )
  83.    )
  84.    (progn
  85.      (setq
  86.        _start_param (vlax-curve-getStartParam _ent)
  87.        _start_hlp_param (+ _start_param 0.00001)
  88.        _end_param (vlax-curve-getEndParam _ent)
  89.        _end_hlp_param (- _end_param 0.00001)
  90.      )
  91.      (cd:BLK_InsertBlock
  92.        (trans (vlax-curve-getStartPoint _ent) 0 1)
  93.        "Example 1"
  94.        nil nil nil
  95.      )
  96.      (LM:setdynpropvalue
  97.        (vlax-ename->vla-object (entlast)) "Angle1"
  98.        (angle
  99.          (vlax-curve-getPointAtParam _ent _start_hlp_param)
  100.          (vlax-curve-getPointAtParam _ent _start_param)
  101.        )
  102.      )
  103.      (cd:BLK_InsertBlock
  104.        (trans (vlax-curve-getEndPoint _ent) 0 1)
  105.        "Example 1"
  106.        nil nil nil
  107.      )
  108.      (LM:setdynpropvalue
  109.        (vlax-ename->vla-object (entlast)) "Angle1"
  110.        (angle
  111.          (vlax-curve-getPointAtParam _ent _end_hlp_param)
  112.          (vlax-curve-getPointAtParam _ent _end_param)
  113.        )
  114.      )
  115.    )
  116. )
  117. (princ)
  118. )

实例图纸
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 16:53:23 | 显示全部楼层
搜索“1st deriv”是一个属性。
 
好的,这是答案
 
  1. (defun alg-ang (obj pnt)
  2. (angle '(0. 0. 0.)
  3.     (vlax-curve-getfirstderiv
  4.       obj
  5.       (vlax-curve-getparamatpoint
  6.         obj
  7.         pnt
  8.       )
  9.     )
  10. )
  11. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 03:28 , Processed in 1.061717 second(s), 56 queries .

© 2020-2025 乐筑天下

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