Jump to content

Recommended Posts

Posted

Hi guys,

I'd like to modify my lisp. I don't know how to do that, I need some help.

My code draws line by distance and azimuth. It's a great code, but it can be better.

I'd like to invoke the command and draw the polygon clockwise just putting distance and azimuth.

The problem for this code is the every time I invoke the code, I have to choose a pick point.

 

Any help will be really greatful!

Thank in advance

:D

 

;;;---------------------------------------------
;;; Rotina para desenhar uma linha com o ângulo
;;;---------------------------------------------
;;; Autolisp Rogério 09/12/04

(defun C:AZI ()
(setvar "cmdecho" 0)
;(setq PT1 (getpoint "Pick o ponto de início: "))
(setq DISTANCIA (getstring "\nDistância: "))
(setq CPTO (STRCAT "@" DISTANCIA "<"))
(setq GRAUS (getstring "\nÂngulo: "))
(setq MINUTOS (getstring "\nMinutos: "))
(setq SEGUNDOS (getstring "\nSegundos: "))
(setq ANG (STRCAT GRAUS "d" MINUTOS "'" SEGUNDOS "\""))
(princ "\nAzimute: ")
(PRINC CPTO)
(PRINC ANG)
(setq LINHA (STRCAT CPTO ANG))
(prompt "\nPick o ponto de início:")
;;(command "Poliline" pause CPTO ANG "")
(command "PLINE" pause LINHA "")
(command "units" 2 2 2 4 270 N "insunits" 0);;Decimal=2/ N°Casas=2/ Sistema Angulo=2/ Fração Angulo=4/ Direção Angulo=0/ Relógio=N
(setvar "cmdecho" 0)
(PRINC)
)
(Princ "\nDigite AZ para iniciar.")
(Princ)


;EXPLICAÇÃO: by Marcio
;================
;Command: -UNITS
;================
; 1. Scientific 1.55E+01
; 2. Decimal 15.50
; 3. Engineering 1'-3.50"
; 4. Architectural 1'-3 1/2"
; 5. Fractional 15 1/2
;With the exception of Engineering and Architectural formats,
;these formats can be used with any basic unit of measurement.
;For example, Decimal mode is perfect for metric units as well
;as decimal English units.
;Enter choice, 1 to 5 <2>:
;--------------------------------------------------------------
;Enter number of digits to right of decimal point (0 to Cool <2>:
;--------------------------------------------------------------
;Systems of angle measure: (Examples)
; 1. Decimal degrees 45.0000
; 2. Degrees/minutes/seconds 45d0'0"
; 3. Grads 50.0000g
; 4. Radians 0.7854r
; 5. Surveyor's units N 45d0'0" E
;Enter choice, 1 to 5 <2>:
;-------------------------------------------------------------- --------
;Enter number of fractional places for display of angles (0 to Cool <4>:
;-------------------------------------------------------------- --------
;Direction for angle 0d0'0":
; East 3 o'clock = 0d0'0"
; North 12 o'clock = 90d0'0"
; West 9 o'clock = 180d0'0"
; South 6 o'clock = 270d0'0"
;Enter direction for angle 0d0'0" <0d0'0">:
;-------------------------------------------
;Measure angles clockwise? [Yes/No] <N>
;-------------------------------------------
;================ ==
;Command: INSUNITS
;==================
;Enter new value for INSUNITS <0>:
;0 Unspecified (No units) = unitless
;1 Inches 

  • Replies 46
  • Created
  • Last Reply

Top Posters In This Topic

  • pBe

    15

  • Madruga_SP

    14

  • hmsilva

    5

  • alanjt

    4

Top Posters In This Topic

Posted Images

Posted

Hi

My file attached can explain better my task, guys.

 

I really appreciate any help.

Thank you

TEST.dwg

Posted
The problem for this code is the every time I invoke the code, I have to choose a pick point.
Did you try simply pressing Enter for the first point? The default is to use the last point entered as the start point for a new line.
Posted

Thanks for replay, neophoible

 

Did you try simply pressing Enter for the first point? The default is to use the last point entered as the start point for a new line.

Yes, I did. But didn't work as I want to.

 

I'd like the lisp insert the direction of lines automatically.

Just choose a point to start and the next points clockwise.

 

I don't know if you understood very well my request.

Sorry for my poor english.

:?

Posted

A suggestion 123.45'57" enter as 123.4557

Fix 123.4557 = 123 degrees

rem = .4557 * 100 =45.57 fix again = 45 minutes

rem = .57 *100 = seconds

angle = deg+min/60+sec/3600

convert all to decimal angle and use in polar function for next point

 

Hard bit Autocad uses radians for angles and is anti clockwise direction

 

code wise (command "pline" pt1) work out next point (command nextpt) last (command "C")

 

If doing change units in other routines as well set up a preloaded defun so 1 line in your code in Civil stuff used all the time.

 

(SETQ ANGBASEE (GETVAR "ANGBASE"))
(SETQ ANGDIRR (GETVAR "ANGDIR"))
(SETQ LUNITSS (GETVAR "LUNITS"))
(SETQ LUPRECC (GETVAR "LUPREC"))
(SETQ AUNITSS (GETVAR "AUNITS"))
(SETQ AUPRECC (GETVAR "AUPREC"))
(SETVAR "LUNITS" 2)
(SETVAR "ANGBASE" (/ pi 2.0))
(SETVAR "ANGDIR" 1)
(SETVAR "LUPREC" 6)
(SETVAR "AUNITS" 0)
(SETVAR "AUPREC" 3)

;
(defun bear (P1)
  (setq ang_ans ""    
     ans_deg ""
     ans_min ""
     char_found ""
     ans_secs "")

 (setq ang_ans (getstring "\nEnter bearing angle in Deg.MMSS :"))

 (setq ans_len (strlen ang_ans))
 (setq x 0)
 (while (/= char_found ".")
   (setq x (+ x 1))
   (setq ans_deg (strcat ans_deg char_found))
   (setq char_found (substr ang_ans x 1))
   (if (= x 9)(setq char_found "."))
  )
  (setq x (+ x 1))
  (setq ans_min (substr ang_ans x 2))
  (setq x (+ x 2))
  (setq ans_secs (substr ang_ans x 2))
      
   (if (= ans_min "")(setq ans_min "0"))
   (if (= ans_secs "")(setq ans_secs "0"))
   (setq ang (dtr (+ (atof ans_deg)(/ (atof ans_min) 60.0)(/ (atof ans_secs) 3600.0))))    
   (setq dist (* (getdist P1 "\nLength of boundary ? (m) :") mm_vs_m))
   (setq p2 (polar p1 ang dist))
   (setq bear_call 1)
)

Posted

Maruga_SP,

 

I have used a similar lisp in my work. This is somewhat along the same objective of the one you are designing. Perhaps the elements in my lisp can help you in your quest.

 

Try this to check whether it can help you.

 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
Autolisp - WCB (whole circle bearing and distance) by Hew Choon Ming at [email="ocean_hew@hotmail.com"]ocean_hew@hotmail.com[/email]; 
2009
;; Draw Setting Out of Lines with Bearing and Distance.
;; Remove 
comments on code if you want circles at each end points, directional bearings 
and distances is labelled at midpt of lines
;;
;; Enter appropriate Text 
height for labelling Azimuths and distances
;; Select or pick points for AZ 
and distances. Labelling is directional and can be clockwise or 
anticlockwise
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


 (princ "Type: WCB to run.")(terpri)
 (princ "Setout WCB and 
Distance Between Points")
 (princ)


(defun C:WCB (/ pt1 pt2 middle DLENGTH aangle APA)
  (setq 
oldsnap (getvar "Osmode")
  oldangdir (getvar 
"angdir")
  oldangbase (getvar "angbase")

)
   (setvar "cmdecho" 0)
   (setvar 
"angdir" 1) ; clockwise
   (setvar "angbase" (/ pi 2)) ; zero 
direction north ; for setting out using bearing, azimuth starts from 
north
;;Get text height for value label
   (setq apa 
(getreal "\n Text Height for value label: "))
   (if apa nil 
(setq apa 3.0))
 (While 
      (Setq 
Pt1 (getpoint "\nPick the Location of Start 
Pt"))(terpri)
      (setq oldsnap1 (getvar 
"Osmode"))
      (setq pt2 (getpoint "\nPick 
Location of End Pt? " pt1))
      (command 
"line" pt1 pt2 "") 


;;(Setq Pt2 (getpoint "Pick the Location of End Pt"))(terpri)


      (Setq middle (List (/ (+ (car pt1) (car 
pt2)) 2.0) (/ (+ (cadr pt1) (cadr pt2)) 
2.0)))
      (Setq Dlength (distance pt1 pt2)) 

      (setq aangle (angle pt1 
pt2))
      (command "Line" Pt1 PT2 "")


;; Remove semi-colon if you want circles at each end points
;;(command 
"circle" PT1 (* Apa 0.5))
;;(command "circle" PT2 (* Apa 0.5))


     (setvar "Osmode" 0) ; no 
snaps
        (If (Or(<= aangle 
(/ pi 2))(>= aangle (* pi 
1.5)))

(progn

(command "text" "j" "Bc" middle apa pt2 (RTOS Dlength 2 
3))

(Setq middleoff (polar middle (+ (angle middle pt2) -1.5708) (* 0.4 
apa)))

(Setq pt2Off (polar pt2 (+ (angle middle pt2) -1.5708)(* 0.4 
apa)))

(command "text" "j" "tc" middleoff apa pt2off (strcat (angtos aangle 1 5) 
">>"))

) ;End progn
         ) ;End 
if


       (if  (And(< aangle (* pi 
1.5))(> aangle (/ pi 
2)))

(progn

(command "text" "j" "Bc" middle apa pt1 (RTOS Dlength 2 
3))
           (Setq 
middleoff (polar middle (+ (angle middle pt1) -1.5708) (* 0.4 
apa)))

(Setq pt1Off (polar pt1 (+ (angle middle pt1) -1.5708) (* 0.4 
apa)))

(command "text" "j" "tc" middleoff apa pt1off (strcat "<<" (angtos aangle 
1 5)))
           ) 
;End progn
        ) ;End 
if
     (setvar "Osmode" oldsnap1)

) ;End while


 (setvar "Osmode" oldsnap)
 (setvar "angdir" 
oldangdir)
 (setvar "angbase" oldangbase)
 (princ)


)

Posted

Thanks for replay guys,

 

@BIGAL

Your code seems to be good for me, but I don't know how to use it.

Do you mind help me, please?

 

@CM Hew

Thanks for sharing your code, but when I load the code, appears a error.

 

; error: no function definition: WHOLE
_$ 

 

Thank you

:)

Posted

Madruga_SP,

 

Somehow, some errors crept in during transfer when posting.

 

Anyway I attach herewith the autolisp WCB for your test drive.

 

Let me know how you get along.

 

The pic shows the results of using WCB. Hope this would be of help.

 

Test1 WCB.jpg

WCB.lsp

Posted
Hi guys,

I'd like to modify my lisp. I don't know how to do that, I need some help.

My code draws line by distance and azimuth. It's a great code, but it can be better.

I'd like to invoke the command and draw the polygon clockwise just putting distance and azimuth.

The problem for this code is the every time I invoke the code, I have to choose a pick point......

 

May i suggest something different:

Launch notepad:

Typed in data

Distance,Angle [angle+minutes+sec]

Distance,Angle [angle+minutes+sec]....

Save file and close notepad

 

 

Prompt for Text Height

Pick start point.

Read file

Bam bam bam.. [draw pline and text]

Close file

 

Done.

 

Sounds easy eh? :)

Posted (edited)

Here you go.

 

(Defun c:demo (/ file opfile a ptlst sp p_ ang ro ptlst pts)
 (setq file (Getfiled "Boundary Data" (getvar 'DWgprefix) "txt" 33))
 (startapp "Notepad" file)
 (setq pts    nil
       ptlst  nil
       opfile (open file "r")
 )
 (While (setq a (read-line opfile))
   (setq ptlst (append ptlst (list (strcase a))))
 )
 (close opfile)
 (if (and ptlst
          (setq sp (getpoint "\nPick Start point:"))
          (setq pts (append pts (list sp)))
          (setq txht (getreal "\nEnter Text height:"))
     )
   (progn
     (command "_pline" sp)
     (foreach itm ptlst
       (command "_non" itm)
       (setq pts (append pts (list (getvar 'Lastpoint))))
     )
     (command "")
     (mapcar '(lambda (j k l)
                (setq str (substr (vl-string-subst " - Az " "<" l) 2)
                      str (vl-string-subst "%%d" "D" str)
                )
                (setq txtD (entmakex
                  (list (cons 0 "TEXT")
                        (cons 10
                              (Setq p_
                                     (polar j (setq ang (angle j k)) (* 0.5 (distance j k)))
                              )
                        )
                        (cons 11 (polar p_ (+ ang (* pi 1.5)) txht))
                        (cons 40 txht)
                        (Cons 50 (if (setq ro (<  (/ pi 2.0)  ang (* pi 1.5))) (+ ang pi) ang))
                        '(72 . 4)
                        '(73 . 3)
                        (cons 1 (if ro (strcat "<< "str)(strcat str " >>")))
                  )
                )
                      )
                
              )
             pts
             (cdr pts)
             ptlst
     )
   )
 )(princ)
)

 

command: Demo

fill the data with this format

@500

@500

@300

@1007.56

 

 

Pick Start point:

Enter Text height: 20

 

HTH

 

AND Another version {using the points collected for String value {angtos}

 

(Defun c:[b]demo2[/b] (/ file opfile a ptlst sp p_ ang ro ptlst)
 (setq file (Getfiled "Boundary Data" (getvar 'DWgprefix) "txt" 33))
 (startapp "Notepad" file)
 (setq pts    nil
       ptlst  nil
       opfile (open file "r")
 )
 (While (setq a (read-line opfile))
   (setq ptlst (append ptlst (list (strcase a))))
 )
 (close opfile)
 (if (and ptlst
          (setq sp (getpoint "\nPick Start point:"))
          (setq pts (append pts (list sp)))
          (setq txht (getreal "\nEnter Text height:"))
     )
   (progn
     (command "_pline" sp)
     (foreach itm ptlst
       (command "_non" itm)
       (setq pts (append pts (list (getvar 'Lastpoint))))
     )
     (command "")
     (mapcar '(lambda[b] (j k)[/b]
               [b] (setq str (angtos (setq ang (angle j k)))
                      str (strcat (rtos (distance j k) 2 2) " - Az "  (vl-string-subst "%%d" "d" str)))[/b]
		(entmakex
                         (list (cons 0 "TEXT")
                               (cons 10
                                     (Setq p_
                                            (polar j
                                                   ang
                                                   (* 0.5 (distance j k))
                                            )
                                     )
                               )
                               (cons 11 (polar p_ (+ ang (* pi 1.5)) txht))
                               (cons 40 txht)
                               (Cons 50
                                     (if (setq ro (< (/ pi 2.0) ang (* pi 1.5)))
                                       (+ ang pi)
                                       ang
                                     )
                               )
                               '(72 . 4)
                               '(73 . 3)
                               (cons 1
                                     (if ro
                                       (strcat "<< " str)
                                       (strcat str " >>")
                                     )
                               )
                         )
                       )
                
              )
             pts
             (cdr pts)
     )
   )
 )
 (princ)
)

 

command: Demo2

Edited by pBe
Alternative code
Posted (edited)

@CM Hew

many thanks for post you code here.

 

I don't have any exist points in my drawing.

I have to edit each distance and azimuth.

e.g.

@26.19

@46.50

@15.75

@42.85

 

@pBe

Thank you for the excellent code!

Works like a charm!

 

If it's not asking too much.

BIGAL said:

123.45'57" enter as 123.4557

Fix 123.4557 = 123 degrees

rem = .4557 * 100 =45.57 fix again = 45 minutes

rem = .57 *100 = seconds

angle = deg+min/60+sec/3600

convert all to decimal angle and use in polar function for next point

This option seems to be excellent for me.

e.g.

Distance:12.50

Azimuth:77.4550

 

Anybody Can help me write a code like that, please?

 

 

Many thanks guys.

You are help me a lot.

:D

Edited by Madruga_SP
Posted

@pBe

Thank you for the excellent code!

Works like a charm!

 

If it's not asking too much.

BIGAL said:

 

Distance:12.50

Azimuth:77.4550....

 

 

Is that directed to me or BIGAL? Does that mean instead of "500 - Az 47d56'3.3" in would show

Distance: 500

Azimuth:

?

Posted (edited)
Is that directed to me or BIGAL? Does that mean instead of "500 - Az 47d56'3.3" in would show

Distance: 500

Azimuth:

?

 

Hi pBe,

BIGAL gave a really good suggestion for the code that sound good to me.

But it's too much to handle, due to my limited knowledge.

So, I'm asking for help to create a lisp.

 

Your code "demo" is wonderful, works perfect.

But I was wondering a code that when I invoke ask for the angle and distance, so draw a polyline after continue the command angle and distance, until finish the poligno.

No need put information above the polyline.

 

e.g.

azimuth:47.5633 (means=47d56'33")

distance:500

Edited by Madruga_SP
Posted

what of 45d2'3"=45.23? or

45d23'3" = 45.233? which digits are for minutes and seconds? how can you tell?

Posted

Hi pBe,

Please, take a look on post#5.

 

BIGAL explain better the task.

 

Kind Regards

:)

Posted
Hi pBe,

Please, take a look on post#5.

 

There's nothing there that answers my Q, It only suggest instead of the original format of 123.45'57" use 123.4557. As you can see we were able to use the former to plot the lines.

 

I guess you're going to have to explain it to me then :)

 

But I was wondering a code that when I invoke ask for the angle and distance, so draw a polyline after continue the command angle and distance, until finish the poligno.

 

That can be arrange, but you need to tell me if you want to stick with the original format for azimuth prompt or use Bigals suggestion

Posted

That can be arrange, but you need to tell me if you want to stick with the original format for azimuth prompt or use Bigals suggestion

 

If I were to draw without using lisp.

 

e.g

Command: pl
PLINE
Specify start point:
Specify next point or [Arc/Halfwidth/Length/Undo/Width]:   @500<90d0'0"
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:   @500<180d0'0"
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]: @500<270d0'0"
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]: @500<360d0'0"
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:ENTER

 

I'd like a lisp doing like this, but more simple.

Input of angle format 123.4557 and distance, using polylines.

 

KInd Regards

Sorry for my poor english

Posted
(defun c:Test (/ p)
 (if (setq p (getpoint "\nSpecify SE corner of square: "))
   (entmakex
     (append (list '(0 . "LWPOLYLINE")
                   '(100 . "AcDbEntity")
                   '(100 . "AcDbPolyline")
                   '(90 . 4)
                   '(70 . 1)
                   (cons 10 (setq p (trans p 1 0)))
             )
             (mapcar (function (lambda (x) (cons 10 (mapcar '+ p x))))
                     '((-500. 0. 0.) (-500. 500. 0.) (0. 500. 0.))
             )
     )
   )
 )
 (princ)
)

Posted
If I were to draw without using lisp

 

I'd like a lisp doing like this, but more simple.

 

I got that part Madruga_SP.

 

Input of angle format 123.4557 and distance, using polylines.

 

This is the part i'm having trouble understanding.

Is it that hard to type in @500 an azimuth equivalent 123.4557 and distance 500? if the only issue the "d" and quote symbols then you can be prompted with 123-45-57, the issue here as shown on post # 14 is the distinction between minutes and seconds. where does one end and the other start?

45.233 ----> 23'3" or 2'33"?

 

Also it appears that you want to "see" the lines being drawn on the screen as oppose to what i suggested and proven to you, input all the values then draw the polyline in one go [much like alanjt's code, can be modified wherein you'll prompted for input THEN draw the polyline].

 

The real issue here me thinks is the ease of typing in the value by avoiding the other symbols. Now if you or Bigal can shed light on the minutes and seconds issue then if should be easy cheesy japanesey.

 

sorry for my poor understanding :)

Posted
where does one end and the other start?

45.233 ----> 23'3" or 2'33"?

 

When you use this system of entering angles, you are very careful to always use two digits for both the minutes and seconds.

 

So 45d3'5" would become 45.0305

 

There are some who insist on having 3 digits for the degrees, and put leading zeroes if necessary.

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