Jump to content

Recommended Posts

Posted

Hi!

 

I am on this forum for almost two months, and you helped me with some problems for which I thank You very much. From the beginning I was thinking of a some script, which probably is not so simple to write. I think, it utilize needs a little math (tangent to a circle) and the length of the polyline.

 

I spend a lot of hours to draw perpendicular lines to lines, arc and polylines using function mirror etc. It would be great if it would work as an offset function in AutoCAD.

 

167w6ra.png

 

The last picture shows the auxiliary dimensions. Every second line has a length of eg 20.

 

I hope, it is not so difficult to help..

  • 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

Posted

Try this .

 

(defun c:test (/ s d i l ang sn pt)
 ;;    Tharwat 11. Mar. 2014    ;;
 (if (setq s (ssget "_+.:S:E" '((0 . "LWPOLYLINE,SPLINE,LINE,ARC"))))
   (progn
     (setq d (/ (vlax-curve-getdistatparam
                  (setq sn (ssname s 0))
                  (vlax-curve-getendparam sn)
                )
                1.5
             )
           i 1.5
           n i
           l '(1.5 7.0)
     )
     (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)
       )
       (entmake
         (list
           '(0 . "LINE")
           (cons 10 pt)
           (cons
             11
             (polar pt (+ ang (* pi 0.5)) (car (setq l (reverse l))))
           )
         )
       )
     )
   )
 )
 (princ)
)
(vl-load-com)

Posted

Thank You! You are so quick! I'm ashamed to ask for fine-tuning. Could you make 4 things?

- give the opportunity to choose which side of the line to be created,

- draw lines in "test" layer,

- give the opportunity to specify a retirement home, length of the first line - now this is 1.5 (I wold like to select between 0 and 1.5 to adapted to other modules).

- give the opportunity to specify "beginning" of the polyline

 

9tk4nb.jpg

 

Last three supplication is not much needed, but cool! (it's make fully comfortable script). Specify side of drawing lines is important.

 

Thank You! :)

Posted

I am too much tired now and it is time to bed here since that it is 10 minutes past midnight , so maybe tomorrow would continue if no one step in and give you a hand to what you are in need of these modifications :)

Posted (edited)

Ok. Thank You!

24mdvmt.png

I guess that if I wanted to select the start of the polyline, and this will be the beginning of another polyline, my polyline will have to be on top to select it. :)

Edited by Wojciech
Posted (edited)

Here we go with a great dynamic presentation . :)

Dynamic.gif

 

(defun c:test (/ *error* Draw_Dynamic_Real s ang sn pt a b d g p gp len x)
 ;;    Tharwat 12. 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 r / 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))
            )
            (if (> sp 0.)
              (setq n sp)
              (setq n i)
            )
            (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 l (reverse l)))
                                     )
                               )
                         )
                )
                (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)
            )
          )
          (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 nil)
          )
          (if (eq (car g) 3)
            (Draw_Dynamic_Real sn d x gp t)
          )
   )
 )
 (redraw)
 (princ)
)
(vl-load-com)

Edited by Tharwat
Posted

Tharwat, Dynamic presentation is indeed fantastic. BTW what software did you use to create this?

Posted
Tharwat, Dynamic presentation is indeed fantastic. BTW what software did you use to create this?

 

Thanks :)

 

It is Camtasia .

Posted

Hi Tharwat! I have problem with your second script. I dont know why it was working only on first time in first file, but after that, it's not working.. First script works!

 

I am putting "test" text in command window, than I see "Specify point at the End Side of Polyline ", after I click, I see "Specify Offset distance", I put 1.5. click Enter, and nothing! Script stop in this moment.

 

And You write this program in beter way than I expected, and I think "Specify Offset distance" could put into code (without puting it in Autocad).

 

Could you correct this? Thank you.

Posted

Is there any error message at the command line ?

Are you sure that the distance you provide is not longer than the object's length ?

Posted

Hope that someone could try the code and tell us about the result :)

Posted
Hope that someone could try the code and tell us about the result :)

Work on my end.

Posted

No problem, any time.

I don't have Camtasia, can you add eye under arc-will looks like blinking eye...

Posted

I don't have Camtasia, can you add eye under arc-will looks like blinking eye...

What are you indicating to ? I did not get it :roll:

Posted

There are no errors. Yes, I am sure. 1.5 I set as a default. Zoom is correct. Line eg. 100 lengh.

 

Command: test
Specify point at the End Side of Polyline :
Specify Offset distance < 1.5 > :
Command:

 

ps. but on first time, it works... now it do not work in any file in Autocad.. Another LISP works corretly

Posted

Ej, Wojtek cos namieszales...

Tharwat, blinking eye....

Posted

Ok, ok, I know where is the problem.. In first start of the script, I cant click enter after "Specify Offset distance :" but I must put own number........

 

Tharwat, could you put "Specify Offset distance " to the code, without putting "Specify Offset distance " in the Autocad? This is not necessary now and it generating this problem.

 

Greets Tharwat and pozdrowienia dla Marka ;)

Posted

I find in this site this lisp

 

(defun C:SLOPE-LINE (/ Talud_boven  Talud_onder afstand afstand_totaal count p1 p2 kleur)

 (defun IS-ON-PL? (ENAME PKT /)
   (vl-catch-all-apply
     'vlax-curve-getdistatpoint
     (list
       ENAME
       PKT
       ) ;_ end of list
     ) ;_ end of vlax-curve-getDistAtPoint
   PKT
   ) ;_ end defun

(vl-load-com)


 (if (and (setq Talud_boven (car (entsel "\nSelect top slope: ")))
          (setq Talud_onder (car (entsel "\nSelect bottom slope: ")))
          (setq afstand (getint "\nLine slope distance:"))
          (setq kleur (acad_colordlg )
          ) ;_ end of and
   
   (progn
     (setq afstand_totaal 0)
     (setq count 0)
     (setq p1 (vlax-curve-getStartPoint
                (vlax-ename->vla-object Talud_boven)
                ) ;_ end of vlax-curve-getStartPoint
           ) ;_ end of setq
     (while p1
       (if (equal (/ count 2.0) (fix (/ count 2.0)) 0.001)
         (setq p2
                (vlax-curve-getClosestPointTo
                  (vlax-ename->vla-object Talud_onder)
                  p1
                  ) ;_ end of vlax-curve-getClosestPointTo
               ) ;_ end of setq
         (setq
           p2 (MAPCAR '(LAMBDA (x) (/ x 2))
                      (MAPCAR '+
                              p1
                              (vlax-curve-getClosestPointTo
                                (vlax-ename->vla-object Talud_onder)
                                p1
                                ) ;_ end of vlax-curve-getClosestPointTo
                              ) ;_ end of MAPCAR
                      ) ;_ end of MAPCAR
           ) ;_ end of setq
         ) ;_ end of if
       (entmake
         (list '(0 . "LINE")
               (cons 10 p1)
               (cons 11 p2)
               ;'(62 . 1) ; standaard kleur
               (cons 62 kleur) ; kleur dia dialog instellen

         ) ;_ end of list
       ) ;_ end of entmake
       (if
         (setq p1 (IS-ON-PL?
                    (vlax-ename->vla-object Talud_boven)
                    (vlax-curve-getpointatdist
                      (vlax-ename->vla-object Talud_boven)
                      (setq afstand_totaal (+ afstand_totaal afstand))
                      ) ;_ end of vlax-curve-getpointatdist
                    ) ;_ end of IS-ON-PL?
               ) ;_ end of setq
          p1
          ) ;_ end of if
       (setq count (1+ count))
       ) ;_ end of while
     ) ;_ end of progn
   ) ;_ end of if
 ) ;_ end of defun

Posted (edited)

I found a strange problem. The script on certain lines does not work.

Command: test
Specify point at the End Side of Polyline :
Specify Offset distance < 1.5 > :
Error: bad argument type: numberp: nil
Command:

ruut74.png

 

Link to DWG:

http://ftp.feniksg.unixstorm.org/wczyszczona_mapa.dwg

 

Tharwat. When you try to fix the problem, please remove "Specify Offset distance" from command line - put it into code.

 

Specify it into code like $variable = 1.5

 

edit: script not working with "lines"?

Edited by Wojciech

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