明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1767|回复: 4

求助,我的程序问题在哪?

[复制链接]
发表于 2003-12-11 11:18:00 | 显示全部楼层 |阅读模式
我想循环子程序的步骤,但不行,请各位大虾指教!!!谢谢!!!


(defun c:zzxyh()
             (setq ocmde (getvar "cmdecho"))
         (setvar "cmdecho" 0)
             (setq num (getint "\n请输入优化直线的数量:"))
             (setq n 1)
             (repeat num
                 (zxyh)
                  (setq n (+ n 1))
              )
             (setvar "cmdecho" ocmde)
             (princ)
)
(defun zxyh()
               (vl-load-com)
               (setq en1 (entsel "\n请选择直线:"))
               (setq n1 (car en1))
               (setq m1 (vlax-ename->vla-object n1))
               (setq start1_point (vlax-curve-getstartpoint m1))
               (setq end1_point (vlax-curve-getendpoint m1))
               (setq refer_point (getpoint "\n请输入靠近直线的起始点的一点:"))
               (setq l1 (distance refer_point start1_point))
               (setq l2 (distance refer_point end1_point))
                (if (<= l1 l2)
                    (progn
                          (setq refer_point (polar end1_point 0 0))
                         (command "line" start1_point end1_point "")
                     )
                     (progn
                          (setq refer_point (polar start1_point 0 0))
                          (command "line" end1_point start1_point "")
                     )
                  )
                  (command "erase" en1)
                  (princ)
)
发表于 2003-12-11 12:03:00 | 显示全部楼层
換這樣看看
剛改寫好的應該沒有問題,
(defun c:zzxyh (/ asdfl)
  (vl-load-com)
  (setvar "cmdecho" 0)
;;;  (setq num (getint "\n請輸入优化直線的數量:"))
  (setq n 0)
  (while (= asdfl nil)
    (setq en1 (entsel "\n請選擇直線:"))
    (if (= en1 nil) (setq asdfl t))
    (zxyh)
    (setq n (1+ n)))
  (setvar "cmdecho" 1)
  (princ))
(defun zxyh ()
  (setq n1 (car en1))
  (setq m1 (vlax-ename->vla-object n1))
  (setq start1_point (vlax-curve-getstartpoint m1))
  (setq end1_point (vlax-curve-getendpoint m1))
;;;  (setq refer_point (getpoint "\n請輸入靠近直線的起始點的一點:"))
  ;------------------------
  (setq  pt (cadr en1)  ent (vlax-ename->vla-object (car en1))
         pt (vlax-curve-getClosestPointTo ent pt) dis (vlax-curve-getDistAtPoint ent pt)
         len (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))
         pt1 (if (< dis (- len dis)) (vlax-curve-getStartPoint ent) (vlax-curve-getEndPoint ent)))
  ;----------------------------
  (if (= (car pt1) (car start1_point))
    (command "line"  end1_point start1_point"")
    (command "line"  start1_point end1_point"")
  )
  (command "circle" start1_point 1)(command "circle" end1_point 2)
  (command "erase" en1 "")
  (princ)
)
 楼主| 发表于 2003-12-13 09:04:00 | 显示全部楼层
BDYCAD大侠:还是不行,我的目的是改变直线的方向(就是需要时对换起点与终点),
我的子程序没问题,但循环不行,还要麻烦你,谢谢!!!
发表于 2003-12-13 09:59:00 | 显示全部楼层
TO morecs:
      你好. 你的程序是循環一次一次去選每條直線再確定哪個端點是所選的線的終點再用命令重新改畫的. 我給你的你執行時只是選那條線就行了. 但選的時候得選你需要的終點靠近那個端點的方向就行了呀. 再看看.
 楼主| 发表于 2003-12-13 11:19:00 | 显示全部楼层
vlax-curve-getClosestPointTo 是不是与vlax-curve-ISClosestPointTo 是同样功能?
谢谢BDYCAD!!!问题解决了!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-10-2 08:41 , Processed in 0.148265 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表