Jump to content

[LISP] Somethig like smart offset


Wojciech

Recommended Posts

The routine does not work on the other line because it has Z coordinates I guess , anyway I updated the code .

 

Try it and let me know .

 

Good luck

Link to comment
Share on other sites

  • Replies 30
  • Created
  • Last Reply

Top Posters In This Topic

  • Tharwat

    14

  • Wojciech

    11

  • mdbdesign

    3

  • shailujp

    1

Top Posters In This Topic

Posted Images

Thank You Tharwat! Script works great!

 

Excellent , happy too hear that . :)

 

I have detected a little problem with "Specify point at the End Side of Polyline". First line is not the longer one all the time. I was describe it in dwg file:

 

That result can not be considered as a problem because the start of the polyline or line is on the other side so the code started drafting lines from start to end and due to the length of the object the last line came by coincidence the shortest at the end and that's why you have the start with the short line first ;)

 

I will see what I can do with it very soon .

Link to comment
Share on other sites

Try this which should meet your new requirements and let me know .

 

(defun c:test (/       *error* Draw_Dynamic_Real       s       ang
              sn      pt      a       b       d       g       p
              gp      len     j       x
             )
 ;;    Tharwat 14. Mar. 2014    ;;
 (defun *error* (x)
   (redraw)
   (if (wcmatch (strcase x) "*EXIT*,*CANCEL*,*BREAK*")
     (princ x)
     (princ (strcat "\n Error: " x))
   )
 )
 (if
   (and
     (setq
       p (getpoint "\n Specify point at the End Side of Polyline :")
     )
     (if (setq s (ssget p '((0 . "LWPOLYLINE,SPLINE,LINE,ARC"))))
       t
       (Alert
         "Pick a point at the end of [ LWPOLYLINE,SPLINE,LINE,ARC ] only ."
       )
     )
   )
    (progn (defun Draw_Dynamic_Real (sn o x sp k r / f d i n l ang pt)
             (setq d (/ (vlax-curve-getdistatparam sn (vlax-curve-getendparam sn))
                        o
                     )
                   i o
                   l (list (* o 0.5) (* o 1.5))
                   f l
             )
             (if (> sp 0.)
               (setq n sp)
               (setq n i)
             )
             (if (= k 0)
               (setq f (reverse f))
               (setq f l)
             )
             (repeat (fix d)
               (setq ang (angle '(0.0 0.0 0.0)
                                (vlax-curve-getfirstderiv
                                  sn
                                  (vlax-curve-getparamatpoint
                                    sn
                                    (setq pt (vlax-curve-getpointatdist sn n))
                                  )
                                )
                         )
                     n   (+ n i)
               )
               (if r
                 (entmake (list '(0 . "LINE")
                                (cons 8 "test")
                                (cons 10 pt)
                                (cons 11
                                      (polar pt
                                             (if x
                                               (+ ang (* pi 0.5))
                                               (+ ang (* pi 1.5))
                                             )
                                             (car (setq f (reverse f)))
                                      )
                                )
                          )
                 )
                 (grdraw pt
                         (polar pt
                                (if x
                                  (+ ang (* pi 0.5))
                                  (+ ang (* pi 1.5))
                                )
                                (car (setq l (reverse l)))
                         )
                         1
                         0
                 )
               )
             )
             (princ)
           )
           (setq d   1.5
                 len (vlax-curve-getdistatparam
                       (setq sn (ssname s 0))
                       (vlax-curve-getendparam sn)
                     )
           )
           (if (< (distance (setq a (vlax-curve-getstartpoint sn)) p)
                  (distance (setq b (vlax-curve-getendpoint sn)) p)
               )
             (setq p  a
                   gp 0.
             )
             (setq p  b
                   gp (rem len d)
                   j  (rem (fix (/ len 1.5)) 2)
             )
           )
           (while (eq (car (setq g (grread t 13 0))) 5)
             (redraw)
             (if (minusp
                   (sin (- (angle p (polar p (angle b a) (/ len 1000.)))
                           (angle p (cadr g))
                        )
                   )
                 )
               (setq x nil)
               (setq x t)
             )
             (Draw_Dynamic_Real sn d x gp j nil)
           )
           (if (eq (car g) 3)
             (Draw_Dynamic_Real sn d x gp j t)
           )
    )
 )
 (redraw)
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

Thank you very much Tharwat. You wrote a script that automatically draws something that is so boring in drawing and there is so much to draw. Your script drew 4,500 strokes today. There is still probably 4 times as much and I think that will draw even an infinite number. The script could be expanded by a further explicit function without end, but it seems to me that you've done enough. I did not foresee little that someone would go so smoothly write the script. Maybe someday could be a play, so the script was more flexible and allow drawing at a certain distance of other things such as dimensions, descriptions, dystance, specific hatch, insert blocks and trim of your line to a lines with a specific layers (if it is possible). Same description that would take me a long time (in the drawing). Maybe someday. I think that I should study programming language lisp.

 

Thank you very much Tharwat.

Link to comment
Share on other sites

Thank you very much Tharwat. You wrote a script that automatically draws something that is so boring in drawing and there is so much to draw. Your script drew 4,500 strokes today. There is still probably 4 times as much and I think that will draw even an infinite number. The script could be expanded by a further explicit function without end, but it seems to me that you've done enough. I did not foresee little that someone would go so smoothly write the script. Maybe someday could be a play, so the script was more flexible and allow drawing at a certain distance of other things such as dimensions, descriptions, dystance, specific hatch, insert blocks and trim of your line to a lines with a specific layers (if it is possible). Same description that would take me a long time (in the drawing). Maybe someday. I think that I should study programming language lisp.

 

Thank you very much Tharwat.

 

Great . I am happy to hear that .

 

You're very welcome any time .

Link to comment
Share on other sites

Nice job Tharwat

 

Wojciech for this job i use this line

 

*line1,-||-||-||-||-||-||-||-||-||-||-||-||-||-||-

A,0.8,["|",STANDARD,s=1,r=0,x=0,y=0.35],0.8,["|",STANDARD,s=0.55,r=0,x=0,y=0.2],0

Link to comment
Share on other sites

  • 2 weeks later...

Hi! I have some problem with using Tharwat's script. It's work perfectly, but it's using polyline to make "offsets". If I have lines, I have to convert them to polylines. I have some script to do this.

;; PolylineJoin.lsp [command name: PJ]
;; Based on c:pljoin by beaufordt from AutoCAD Customization Discussion Group
;; Streamlined by Kent Cooper, June 2011
(defun C:PJ (/ cmde peac ss); = Polyline Join
 (princ "\nTo join touching objects into Polyline(s) [pick 1 to join all possible objects to it],")
 (setq
   ss (ssget '((0 . "LINE,ARC,*POLYLINE")))
   cmde (getvar 'cmdecho)
   peac (getvar 'peditaccept)
 ); end setq
 (setvar 'cmdecho 0)
 (setvar 'peditaccept 1)
 (if ss
   (if (= (sslength ss) 1)
     (command "_.pedit" ss "_join" "_all" "" ""); then
     (command "_.pedit" "_multiple" ss "" "_join" "0.0" ""); else
   ); end inner if
 ); end outer if
 (setvar 'cmdecho cmde)
 (setvar 'peditaccept peac)
 (princ)
); end defun

But this script has one drawback. It combines all of the lines that are adjacent to each other.

 

Could you edit this script to make something like this:

xdwfhg.png

 

2ewmkhw.png

 

20qnm0i.png

 

At this moment script working like this:

2n7mkuf.png

 

I would like to connect to polyline lines on the same style, color and layer only.

Link to comment
Share on other sites

(if (setq s (ssget p '((0 . "[color=red]LWPOLYLINE,SPLINE,LINE,ARC[/color]"))))

 

Hi! I have some problem with using Tharwat's script. It's work perfectly, but it's using polyline to make "offsets". If I have lines, I have to convert them to polylines. I have some script to do this.

 

 

That's not true at all , you are looking for something completely different with your last reply so you can not say that my routine does not work with lines or only with Polylines , the highlighted Object names from

my last routine supports what I am saying . :glare:

Link to comment
Share on other sites

No. No. No. You misunderstand me now. :) I'm glad you're here again. Look. If I need to make a smart offset on the line, I'm doing it on the line. If I need to do it on the arc I'm doing it on the arc. But often I operate polylines. I'm getting from other workers lines and arcs and I need in a controlled way to connect lines and arcs in polylines. I'm doing it with this script, which is not perfect for me, so I would like to ask for it improvement.

I wish I hadn't started a separate thread, because only You messed up in the head. Your script works exactly like I wanted and I thank you for it very much, but apart from that I need tool to connect the line to polylines when I operate adjoining lines and arcs. I do not want it to be added to the code in your script, because I want to control it.

Do you understand now? Sorry for my english. :)

I'm leaving for a few days. Yours sincerely.

 

edit: On those screens are visible separate lines that are combined into polylines. The idea is that by clicking on the first line or arc merged into polylines but with lines or arcs of the same layer, style and color.

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...