Jump to content

Spatial grid segmentation


myloveflyer

Recommended Posts

I found a program, but the running program has an error "Error: parameter type error: 2D / 3D point: nil", the graphic is attached, some graphics can form a grid, some graphics have errors, I don't know why, can someone help I see why there are errors or are there other programs that can be completed?

;;;From http://www.theswamp.org by ribarm
(defun c:surfedge ( / osm c1 c2 c3 c4 m n _edges _pt lp1 lp2 lp3 lp4 i j pt1 pt2 pt3 pt4 )
 
  (vl-load-com)
 
  (setq osm (getvar 'osmode))
  (setvar 'osmode 0)
  (while (not (setq c1 (car (entsel "\nPick 1st curve edge")))))
  (while (not (setq c2 (car (entsel "\nPick 2nd curve edge")))))
  (while (not (setq c3 (car (entsel "\nPick 3rd curve edge")))))
  (while (not (setq c4 (car (entsel "\nPick 4th curve edge")))))
  (initget 7)
  (setq m (getint "\nSpecify number of segments along 1st and 3rd curves direction : "))
  (initget 7)
  (setq n (getint "\nSpecify number of segments along 2nd and 4th curves direction : "))
 
  (defun _edges ( c1 c2 c3 c4 m n / k mm nn lp1 lp2 lp3 lp4 )
    (setq k -1)
    (while (< k m)
      (setq mm (cons (setq k (1+ k)) mm))
    )
    (setq k -1)
    (while (< k n)
      (setq nn (cons (setq k (1+ k)) nn))
    )
    (setq lp1 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c1 x)) 
                       (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c1) x))
                                (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c1) (vlax-curve-getstartparam c1)) x))
                                         (mapcar '(lambda ( x ) (/ x (float m)))
                                                  (reverse mm)
                                         )
                                )
                       )
              )
    )
    (setq lp2 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c2 x)) 
                       (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c2) x))
                                (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c2) (vlax-curve-getstartparam c2)) x))
                                         (mapcar '(lambda ( x ) (/ x (float n)))
                                                  (reverse nn)
                                         )
                                )
                       )
              )
    )
    (setq lp3 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c3 x)) 
                       (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c3) x))
                                (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c3) (vlax-curve-getstartparam c3)) x))
                                         (mapcar '(lambda ( x ) (/ x (float m)))
                                                  (reverse mm)
                                         )
                                )
                       )
              )
    )
    (setq lp4 (mapcar '(lambda ( x ) (vlax-curve-getpointatparam c4 x)) 
                       (mapcar '(lambda ( x ) (+ (vlax-curve-getstartparam c4) x))
                                (mapcar '(lambda ( x ) (* (- (vlax-curve-getendparam c4) (vlax-curve-getstartparam c4)) x))
                                         (mapcar '(lambda ( x ) (/ x (float n)))
                                                  (reverse nn)
                                         )
                                )
                       )
              )
    )
    (list lp1 lp2 lp3 lp4)
  )
 
  (defun _pt ( lp1 lp2 lp3 lp4 a b / p10 p20 p30 p40 p1 p2 p3 p4 p1p p2p p3p p4p pp p1e p2e p3e p4e p13ez p24ez ppez p13z p24z ppz pt )
    (setq p10 (nth 0 lp1))
    (setq p20 (nth 0 lp2))
    (setq p30 (nth 0 lp3))
    (setq p40 (nth 0 lp4))
    (setq p1 (nth a lp1))
    (setq p2 (nth b lp2))
    (setq p3 (nth (- m a) lp3))
    (setq p4 (nth (- n b) lp4))
    (setq p1p (mapcar '- p1 (list 0.0 0.0 (caddr p1))))
    (setq p2p (mapcar '- p2 (list 0.0 0.0 (caddr p2))))
    (setq p3p (mapcar '- p3 (list 0.0 0.0 (caddr p3))))
    (setq p4p (mapcar '- p4 (list 0.0 0.0 (caddr p4))))
    (setq pp (inters p1p p3p p2p p4p t))
    (setq p1e (inters p10 p20 p1p (mapcar '+ p1p '(0.0 0.0 1.0)) nil))
    (setq p2e (inters p20 p30 p2p (mapcar '+ p2p '(0.0 0.0 1.0)) nil))
    (setq p3e (inters p30 p40 p3p (mapcar '+ p3p '(0.0 0.0 1.0)) nil))
    (setq p4e (inters p40 p10 p4p (mapcar '+ p4p '(0.0 0.0 1.0)) nil))
    (setq p13ez (caddr (inters p1e p3e pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
    (setq p24ez (caddr (inters p2e p4e pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
    (setq ppez (/ (+ p13ez p24ez) 2.0))
    (setq p13z (caddr (inters p1 p3 pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
    (setq p24z (caddr (inters p2 p4 pp (mapcar '+ pp '(0.0 0.0 1.0)) nil)))
    (setq ppz (- (+ p13z p24z) ppez))
    (setq pt (list (car pp) (cadr pp) ppz))
    pt
  )
 
  (setq lp1 (car (_edges c1 c2 c3 c4 m n)))
  (setq lp2 (cadr (_edges c1 c2 c3 c4 m n)))
  (setq lp3 (caddr (_edges c1 c2 c3 c4 m n)))
  (setq lp4 (cadddr (_edges c1 c2 c3 c4 m n)))
 
  (setq i -1)
  (repeat m
    (setq j -1)
    (setq i (1+ i))
    (repeat n
      (setq j (1+ j))
      (setq pt1 (_pt lp1 lp2 lp3 lp4 i j))
      (setq pt2 (_pt lp1 lp2 lp3 lp4 (1+ i) j))
      (setq pt3 (_pt lp1 lp2 lp3 lp4 (1+ i) (1+ j)))
      (setq pt4 (_pt lp1 lp2 lp3 lp4 i (1+ j)))
      (command "_.3dface" pt1 pt2 pt3 pt4 "")
    )
  )
 
  (setvar 'osmode osm)
  (princ)
)

 

test.dwg

Link to comment
Share on other sites

It doesn't find an intersection point at this line (if you first select the line, then the arc):

 

(setq p1e (inters p10 p20 p1p (mapcar '+ p1p '(0.0 0.0 1.0)) nil))

 

Not sure if this helps much.

Link to comment
Share on other sites

13 hours ago, Emmanuel Delay said:

It doesn't find an intersection point at this line (if you first select the line, then the arc):

 

(setq p1e (inters p10 p20 p1p (mapcar '+ p1p '(0.0 0.0 1.0)) nil))

 

Not sure if this helps much.

HI,Emmanuel Delay,Sure enough, there is no intersection, but when I draw the line between the arcs, I draw it by capturing the end points of the arc. There should be no gap between the line and the arc. I don’t know why the program can’t run

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...