Author Topic: What info do I need to create an spline with entmake?  (Read 1919 times)

0 Members and 1 Guest are viewing this topic.

Brick_top

  • Guest
What info do I need to create an spline with entmake?
« on: January 20, 2011, 09:30:21 AM »
I'm trying to learn mapcar and lambda and was exercising by creating some routines.

But I'm stuck in creating a spline with entmake:

Here is what I have by now

Code: [Select]
(defun c:xypl (/ ptlstf2 ptlsft)

  (vl-load-com)
  (setq ss1 (ssget (list (cons -4 "<or")(cons 0 "LWPOLYLINE")(cons 0 "SPLINE")(cons -4 "or>")))
dxf (getdist "\nDistância em X Final")
dyf (getdist "\nDistãncia em Y Final")
        num 0
  );setq

    (setq ptlst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget (ssname ss1 num)))))
      (if
(= (cdr (assoc 0 (entget (ssname ss1 num)))) "SPLINE")
    (setq ptlst (mapcar 'reverse (mapcar 'cdr (mapcar 'reverse ptlst)))
                  ptlst2 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 11 (car x))) (entget (ssname ss1 num))))
          ptlst3 (mapcar 'reverse (mapcar 'cdr (mapcar 'reverse ptlst2)))
          pminx2 (assoc (apply 'min (mapcar 'car ptlst3)) ptlst3)
          pmaxx2 (assoc (apply 'max (mapcar 'car ptlst3)) ptlst3)
          ptlsty2 (mapcar 'reverse ptlst3)
          pminy2 (reverse (assoc (apply 'min (mapcar 'car ptlsty2)) ptlsty2))
          pmaxy2 (reverse (assoc (apply 'max (mapcar 'car ptlsty2)) ptlsty2))
          distx2 (distance pminx2 (list (car pmaxx2)(cadr pminx2)))
          disty2 (distance pminy2 (list (car pminy2)(cadr pmaxy2)))
          xper2 (/ dxf distx2)
          yper2 (/ dyf disty2)
          ptlstf2 (mapcar '(lambda (x) (list (* (car x) xper2)(* (cadr x) yper2))) ptlst2)
    );setq
);if
    (setq pminx (assoc (apply 'min (mapcar 'car ptlst)) ptlst)
  pmaxx (assoc (apply 'max (mapcar 'car ptlst)) ptlst)
          ptlsty (mapcar 'reverse ptlst)
  pminy (reverse (assoc (apply 'min (mapcar 'car ptlsty)) ptlsty))
  pmaxy (reverse (assoc (apply 'max (mapcar 'car ptlsty)) ptlsty))
  distx (distance pminx (list (car pmaxx) (cadr pminx)))
  disty (distance pminy (list (car pminy) (cadr pmaxy)))
  xper (/ dxf distx)
  yper (/ dyf disty)
  ptlstf (mapcar '(lambda (x) (list (* (car x) xper)(* (cadr x) yper))) ptlst)
    );setq


 

  ; (setq vl
  ;         (list
  ;         (cons 0 "LWPOLYLINE")
  ;         (cons 8 "layer")
  ;         (cons 100 "AcDbEntity")
  ;         (cons 100 "AcDbPolyline")
  ;         (cons 90 (length ptlstf))
  ;         (cons 70 0)
  ;    (cons 62 10)
  ;         (cons 43 0.0)
  ;         )
  ;      )
    (setq vl
           (list
           (cons 0 "SPLINE")
           (cons 8 "layer")
           (cons 100 "AcDbEntity")
           (cons 100 "AcDbSPLINE")
   (cons 73 (length ptlstf2))
           (cons 74 (length ptlstf))
           (cons 70 0)
   (cons 62 10)
           (cons 43 0.0)
           )
        )
   
    (foreach le ptlstf2 (setq vl (append vl (list (cons 10 le)) )) )
    (foreach le ptlstf (setq vl (append vl (list (cons 11 le)) )) )

     (entmake vl)
    (setq vl (entlast))
    (command "move" vl "" (car ptlstf)(car ptlst))
   
  );defun
Here is the entmake part
Code: [Select]
(setq vl
           (list
           (cons 0 "SPLINE")
           (cons 8 "layer")
           (cons 100 "AcDbEntity")
           (cons 100 "AcDbSPLINE")
   (cons 73 (length ptlstf2))
           (cons 74 (length ptlstf))
           (cons 70 0)
   (cons 62 10)
           (cons 43 0.0)
           )
        )
   
    (foreach le ptlstf2 (setq vl (append vl (list (cons 10 le)) )) )
    (foreach le ptlstf (setq vl (append vl (list (cons 11 le)) )) )

     (entmake vl)



edit - I only put the rest of the code here so you could see where the variables come from
« Last Edit: January 20, 2011, 10:58:02 AM by Brick_top »

Brick_top

  • Guest
Re: What info do I need to create an spline with entmake?
« Reply #1 on: January 20, 2011, 09:57:12 AM »
I'm reading the documentation where there is the list of the entity codes in a spline

I was just hoping I wouldn't have to use most of them

I don't understand many of them  :|
« Last Edit: January 20, 2011, 10:08:21 AM by Brick_top »

Brick_top

  • Guest
Re: What info do I need to create an spline with entmake?
« Reply #2 on: January 20, 2011, 11:11:37 AM »
I think I have sort of did it using this:
Code: [Select]
(setq vl
           (list
           (cons 0 "SPLINE")
           (cons 8 "layer")
           (cons 100 "AcDbEntity")
           (cons 100 "AcDbSpline")
   (cons 73 (length ptlstf2))
           (cons 74 (length ptlstf))
   (cons 62 10)
   (cons 70 8)
   (cons 71 3)
           )
        )

I guess I had code 70 wrong  and was missing code 71. I also had to remove code 43

It now creates an spline but I guess I must be missing some other calculations.

with this routine I was trying to change scales in X and Y, I guess there is some math I would need to do the calculations for the rest of the codes
« Last Edit: January 20, 2011, 11:24:10 AM by Brick_top »