Author Topic: Polyline Cut Line  (Read 4980 times)

0 Members and 1 Guest are viewing this topic.

Noel

  • Mosquito
  • Posts: 9
Polyline Cut Line
« on: May 03, 2014, 02:02:25 PM »
This is my first post some of my code. I am stuck and nee help.
I am going to use this in both ACAD and BricsCAD.
In BricsCAD I get this error :

Automation Error 80020009; [IAcadModelSpace] Error accessing [ADDPOLYLINE] method. ErrIndex=0;
The parameter is incorrect.

I appreciate any help thanks

Noel

Code - Auto/Visual Lisp: [Select]
  1. (defun C:BL (/ P1 P2 P3 P4 P5 P6 P7 ptlist mspace)
  2.  
  3.   (setq OSPM (getvar "osmode"))
  4.   (setvar "OSMODE" 0)
  5.   (setvar "cmdecho" 0)
  6.  
  7.  
  8.   (setq mspace (vla-get-Modelspace thisdrawing))
  9.  
  10.   (setq P1 (getpoint "\nEnter 1st point of break line: "))
  11.   (Error_New)
  12.  
  13.   (setq P2 (getpoint P1 "\nEnter 2nd point of break line: "))
  14.   (Error_New)
  15.  
  16.   (setq D (getdist P2 "\nEnter zig-zag length rel to p2: "))
  17.   (Error_New)
  18.  
  19.   (setq AN (angle P1 P2))               ;direction of line
  20.   (setq L (/ (distance P1 P2) 2))       ;dist/2
  21.   (setq C (/ D 2))                      ;zig-zag/2
  22.   (setq L (- L C))                      ;l-c
  23.   (setq P3 (polar P1 AN L))
  24.   (setq P6 (polar P3 AN D))
  25.   (setq P7 (polar P3 AN C))
  26.   (setq P4 (polar P7 (+ AN (DTR 90)) D))
  27.   (setq P5 (polar P7 (- AN (DTR 90)) D))
  28.  
  29.   (setq pt-list (list P1 P3 P4 P5 P6 P2))
  30.  
  31.        
  32.         (setq tmp (vlax-make-safearray vlax-vbDouble '(0 . 21)))
  33.         (vlax-safearray-fill tmp '(pt-list))
  34.         (setq obj (vla-addPolyline mspace tmp))
  35.  
  36.   (setvar "osmode" OSPM)
  37. )

mailmaverick

  • Bull Frog
  • Posts: 495
Re: Polyline Cut Line
« Reply #1 on: May 03, 2014, 02:27:03 PM »
I made a routine quite long ago which makes a breakline. Check if it works for you.

Arguments :
p1 = First point of breakline
p2 = Second point of breakline
siz = Size of break symbol
ext = Extension of breakline from given points

Code - Auto/Visual Lisp: [Select]
  1. (defun makebreaklines (p1 p2 siz ext)
  2. (setq size (atof siz))
  3. (setq extn (atof ext))
  4. (setq p1x (car p1) p1y (cadr p1))
  5. (setq p2x (car p2) p2y (cadr p2))
  6. (setq ang1 (angle p2 p1))
  7. (setq p3x (+ p1x (* extn (cos ang1))))
  8. (setq p3y (+ p1y (* extn (sin ang1))))
  9. (setq p3 (list p3x p3y))
  10. (setq ang2 (angle p1 p2))
  11. (setq p4x (+ p2x (* extn (cos ang2))))
  12. (setq p4y (+ p2y (* extn (sin ang2))))
  13. (setq p4 (list p4x p4y))
  14. (setq p5x (/ (+ p1x p2x) 2))
  15. (setq p5y (/ (+ p1y p2y) 2))
  16. (setq p5 (list p5x p5y))
  17. (setq df (/ extn 2))
  18. (setq p6x (+ p5x (* df (cos ang1))))
  19. (setq p6y (+ p5y (* df (sin ang1))))
  20. (setq p6 (list p6x p6y))
  21. (setq p7x (+ p5x (* df (cos ang2))))
  22. (setq p7y (+ p5y (* df (sin ang2))))
  23. (setq p7 (list p7x p7y))
  24. (setq df (/ extn 4))
  25. (setq tmp1x (+ p5x (* df (cos ang1))))
  26. (setq tmp1y (+ p5y (* df (sin ang1))))
  27. (setq tmp1 (list tmp1x tmp1y))
  28. (setq tmp2x (+ p5x (* df (cos ang2))))
  29. (setq tmp2y (+ p5y (* df (sin ang2))))
  30. (setq tmp2 (list tmp2x tmp2y))
  31. (setq df (* size 0.6875))
  32. (setq qw (+ ang1 (/ pi 2)))
  33. (setq ty (+ ang2 (/ pi 2)))
  34. (setq p8x (+ tmp1x (* df (cos qw))))
  35. (setq p8y (+ tmp1y (* df (sin qw))))
  36. (setq p8 (list p8x p8y))
  37. (setq p9x (+ tmp2x (* df (cos ty))))
  38. (setq p9y (+ tmp2y (* df (sin ty))))
  39. (setq p9 (list p9x p9y))
  40. (setq plist (list p3 p6 p8 p9 p7 p4))
  41. (setq vl (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length plist)) (cons 70 0) (cons 43 0.0)))
  42. (setq GCList (mapcar '(lambda (coord) (cons 10 coord)) plist))
  43. (setq vl (append vl GCList))
  44. (entmake vl)
  45. )
  46.  
  47.  

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Polyline Cut Line
« Reply #2 on: May 03, 2014, 02:55:47 PM »
Automation Error 80020009; [IAcadModelSpace] Error accessing [ADDPOLYLINE] method. ErrIndex=0;
The parameter is incorrect.

Have you tried sending a support request, Torsten is very quick and accurate in his reply's.

Noel

  • Mosquito
  • Posts: 9
Re: Polyline Cut Line
« Reply #3 on: May 03, 2014, 04:17:26 PM »
Thanks for the reprises.
I haven sent a support request to  Torsten as my first thought was that i have made a mistake some were in the code and cant see it.

Mailmaverick I will take a look at your code.
its just that at this point I'm like a dog with a bone. I don't like things that don't work and i wont to know Y

ymg

  • Guest
Re: Polyline Cut Line
« Reply #4 on: May 03, 2014, 09:46:33 PM »
Noel,

Your problem is in the safearray.

You are trying to fill a one dimension safearray with a list of list.

You would be much better simply entmaking the polyline.

Safearray are a pity, slow and awkward.

Code: [Select]
(defun C:BL (/ );P1 P2 P3 P4 P5 P6 P7 ptlist mspace)
 
  (setq OSPM (getvar "osmode"))
  (setvar "OSMODE" 0)
  (setvar "cmdecho" 0)
 
  (setq P1 (getpoint "\nEnter 1st point of break line: "))
  ;(Error_New)
 
  (setq P2 (getpoint P1 "\nEnter 2nd point of break line: "))
  ;(Error_New)
 
  (setq D (getdist P2 "\nEnter zig-zag length rel to p2: "))
  ;(Error_New)
 
  (setq AN (angle P1 P2)) ;direction of line
  (setq L (/ (distance P1 P2) 2)) ;dist/2
  (setq C (/ D 2)) ;zig-zag/2
  (setq L (- L C)) ;l-c
  (setq P3 (polar P1 AN L))
  (setq P6 (polar P3 AN D))
  (setq P7 (polar P3 AN C))
  (setq P4 (polar P7 (+ AN (DTR 90)) D))
  (setq P5 (polar P7 (- AN (DTR 90)) D))
 
  (mk_lwp (list P1 P3 P4 P5 P6 P2))
 
 

  (setvar "osmode" OSPM)
)

;;******************************************************************************;
;; mk_lwp    by Alan J Thompson                                                 ;
;; Argument: pl, A list of points (2d or 3d)                                    ;
;; Create an LWPolyline at Elevation 0, on Current Layer.                       ;
;; Return: ename of lwpolyline                                                  ;
;;******************************************************************************;

(defun mk_lwp (pl)
   
      (entmakex
         (append (list '(0 . "LWPOLYLINE")
                       '(100 . "AcDbEntity")
                       '(100 . "AcDbPolyline")
                        (cons 90 (length pl))
                        '(70 . 0)
                 )
                 (mapcar '(lambda (p) (cons 10 (trans (list (car p) (cadr p)) 1 0))) pl)
        )
      )
   
 )

I had to comment out (error_new) as you did not provide it.

ymg
« Last Edit: May 03, 2014, 09:53:54 PM by ymg »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Polyline Cut Line
« Reply #5 on: May 03, 2014, 10:52:08 PM »
Something to look at when you finish your lisp.
http://www.theswamp.org/index.php?topic=37531
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Polyline Cut Line
« Reply #6 on: May 04, 2014, 12:11:33 AM »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Polyline Cut Line
« Reply #7 on: May 04, 2014, 03:24:22 AM »
Ymg is right about the 'list of lists'. But there is also an issue with the u-bound of the safearray. Because there are 6 points it should be 17 instead of 21.

According to the docs vla-addpolyline requires a variant. But in BricsCAD vlax-make-variant is not required. In fact BricsCAD does not even require the safearray.

I am surprised that the code works in AutoCAD.

Code: [Select]
(setq tmp (vlax-make-safearray vlax-vbDouble '(0 . 17)))
(vlax-safearray-fill tmp (apply 'append pt-list))
(setq obj (vla-addpolyline mspace (vlax-make-variant tmp)))

In BricsCAD this also works:
Code: [Select]
(setq obj (vla-addpolyline mspace (apply 'append pt-list)))
Note: there is no need for:
Code: [Select]
(setvar "OSMODE" 0)
(setvar "cmdecho" 0)
...
(vlax-release-object obj)

ymg

  • Guest
Re: Polyline Cut Line
« Reply #8 on: May 04, 2014, 10:12:03 AM »
Roy,

I don't know about BricsCAD, but in Vanilla I have yet to find
where safearray are useful or cannot be replaced by something else.

Everything I've tried with it is slow like molasses.

@Noel

Do try Cab's link above, should settle your need for breaklines
for the next century.

ymg

Noel

  • Mosquito
  • Posts: 9
Re: Polyline Cut Line
« Reply #9 on: May 04, 2014, 11:40:38 AM »
Thanks Guys
CAB your link !!! well in the 20 year I've been drafting I've never had to yous that many
you've left me much to think about Thanks

Noel


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Polyline Cut Line
« Reply #10 on: May 06, 2014, 03:49:06 AM »
I don't know about BricsCAD, but in Vanilla I have yet to find
where safearray are useful or cannot be replaced by something else.

Everything I've tried with it is slow like molasses.

You are right that it is slower. But not by that much in BricsCAD:

Code: [Select]
Benchmarking .......... elapsed milliseconds / relative timing <5000 iterations>

  (POLYTEST_ENTMAKE) ........... 610 / 1.69 <fastest>
  (POLYTEST_VL_VARIANT) ........ 859 / 1.20
  (POLYTEST_VL_SAFEARRAY) ...... 969 / 1.06
  (POLYTEST_VL_LIST) .......... 1031 / 1.00 <slowest>

Code: [Select]
(defun PolyTest_Entmake ( / lst)
  (setq lst '((0.0 0.0 0.0) (1.0 0.0 0.0) (1.0 1.0 0.0) (0.0 1.0 0.0)))
  (mk_lwp lst)
)

(defun PolyTest_VL_variant ( / lst)
  (setq lst '((0.0 0.0 0.0) (1.0 0.0 0.0) (1.0 1.0 0.0) (0.0 1.0 0.0)))
  (VL_variant_mk_lwp lst)
)

(defun PolyTest_VL_safearray ( / lst)
  (setq lst '((0.0 0.0 0.0) (1.0 0.0 0.0) (1.0 1.0 0.0) (0.0 1.0 0.0)))
  (VL_safearray_mk_lwp lst)
)

(defun PolyTest_VL_list ( / lst)
  (setq lst '((0.0 0.0 0.0) (1.0 0.0 0.0) (1.0 1.0 0.0) (0.0 1.0 0.0)))
  (VL_list_mk_lwp lst)
)

(defun VL_variant_mk_lwp (pl)
  (vla-addlightweightpolyline
    (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray vlax-vbdouble (cons 0 (1- (* (length pl) 2))))
        (apply 'append (mapcar '(lambda (p) (list (car p) (cadr p))) pl))
      )
    )
  )
)

(defun VL_safearray_mk_lwp (pl)
  (vla-addlightweightpolyline
    (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-safearray-fill
      (vlax-make-safearray vlax-vbdouble (cons 0 (1- (* (length pl) 2))))
      (apply 'append (mapcar '(lambda (p) (list (car p) (cadr p))) pl))
    )
  )
)

(defun VL_list_mk_lwp (pl)
  (vla-addlightweightpolyline
    (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-safearray-fill
      (vlax-make-safearray vlax-vbdouble (cons 0 (1- (* (length pl) 2))))
      (apply 'append (mapcar '(lambda (p) (list (car p) (cadr p))) pl))
    )
  )
)

;; Adapted: removed trans.
;;******************************************************************************;
;; mk_lwp    by Alan J Thompson                                                 ;
;; Argument: pl, A list of points (2d or 3d)                                    ;
;; Create an LWPolyline at Elevation 0, on Current Layer.                       ;
;; Return: ename of lwpolyline                                                  ;
;;******************************************************************************;
(defun mk_lwp (pl)
  (entmakex
    (append
      (list
        '(0 . "LWPOLYLINE")
        '(100 . "AcDbEntity")
        '(100 . "AcDbPolyline")
        (cons 90 (length pl))
        '(70 . 0)
      )
      (mapcar '(lambda (p) (list 10 (car p) (cadr p))) pl)
    )
  )
)

ymg

  • Guest
Re: Polyline Cut Line
« Reply #11 on: May 06, 2014, 09:47:27 AM »
Roy,

Interesting!  your speed test.

A second cause for my hatred of safearray is the verbosity of it all.

There are however case where array would be the way to go, specially
when there are frequent update to the value, of well dimensioned array.

BricsCAD seems to be more committed to improving Lisp than Autodesk,
I am seriously considering moving to it.

ymg

mailmaverick

  • Bull Frog
  • Posts: 495
Re: Polyline Cut Line
« Reply #12 on: May 06, 2014, 11:26:52 AM »

Do try Cab's link above, should settle your need for breaklines
for the next century.

ymg

Absolutely rightly said. Dear CAB, I want to thank God for giving birth to people like you on this Earth.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Polyline Cut Line
« Reply #13 on: May 06, 2014, 12:04:20 PM »
Thank you for such high praise.
Makes my heart smile.  :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Noel

  • Mosquito
  • Posts: 9
Re: Polyline Cut Line
« Reply #14 on: June 05, 2014, 05:18:40 AM »
Finally got this finished and all the bugs worked out Yes some will say I’m slow I don’t write lisp professionally.
Sow hear is the final result some on my find it useful.
Thank for all the help and suggestions I appreciate it .
Noel

hanhphuc

  • Newt
  • Posts: 64
Re: Polyline Cut Line
« Reply #15 on: June 05, 2014, 11:08:16 AM »
Thank you for such high praise.
Makes my heart smile.  :)

hi mr. Charles Alan Butler
your hard work should be appreciated  :-)
as well as all ppl shared their ideas & knowledge here. thank you
( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments