Jump to content

how to link attribute block with lisp


satishrajdev

Recommended Posts

hi,

i need one help to sort out my problem, i have a routine which is given below which gives latitude and longitude on my drawing.

(defun C:GDMS ()

 (setq lonzone (getint "\n Enter Zone:"))

 (initget "N S")
 (setq Hem (getkword "\n Enter the Hemisphere (S/N):"))

 (setq Pnt (Getpoint "\n Specify Point:"))

 (setq Xval (car Pnt))

 (setq Yval (car (cdr Pnt)))

 (if (= Hem "S")
   (setq Y (- 10000000 Yval))
   (setq Y Yval)
 )

 (if (and (or (= Hem "S") (= Hem "N")) (= Yval 0.0))
   (progn
     (setq Y Yval)
     (setq Hem "Equator")
   )
   (progn
     (setq Y Y)
     (Setq Hem Hem)
   )
 )


 (setq b 6356752.3142)

 (setq a 6378137.0)

 (setq X (- 500000.0 Xval))

 (setq e (sqrt (- 1.0 (expt (/ b a) 2.0))))

 (setq k0 0.9996)

 (setq meridional-arc (/ Y k0))

 (setq	mu (/ meridional-arc
      (* a
	 (- 1
	    (/ (expt e 2) 4)
	    (/ (* 3 (expt e 4)) 64)
	    (/ (* 5 (expt e 6)) 256)
	 )
      )
   )
 )

 (setq	e1 (/ (- 1 (expt (- 1 (expt e 2)) 0.5))
      (+ 1 (expt (- 1 (expt e 2)) 0.5))
   )
 )

 (setq j1 (- (/ (* 3 e1) 2) (/ (* 27 (expt e1 3)) 32)))

 (setq j2 (- (/ (* 21 (expt e1 2)) 16) (/ (* 55 (expt e1 4)) 32)))

 (setq j3 (/ (* 151 (expt e1 3)) 96))

 (setq j4 (/ (* 1097 (expt e1 4)) 512))

 (setq	footprint-latitude
 (+ mu
    (* j1 (sin (* 2.0 mu)))
    (* j2 (sin (* 4.0 mu)))
    (* j3 (sin (* 6.0 mu)))
    (* j4 (sin (* 8.0 mu)))
 )
 )

 (setq eprime2 (/ (* e e) (- 1.0 (* e e))))

 (setq c1 (* eprime2 (expt (cos footprint-latitude) 2)))

 (setq	t1 (expt (/ (sin footprint-latitude) (cos footprint-latitude))
	 2
   )
 )

 (setq	r1 (/ (* a (- 1 (expt e 2)))
      (expt (- 1
	       (* (expt e 2)
		  (expt (sin footprint-latitude) 2)
	       )
	    )
	    1.5
      )
   )
 )

 (setq	n1 (/ a
      (expt (- 1
	       (* e
		  e
		  (sin footprint-latitude)
		  (sin footprint-latitude)
	       )
	    )
	    0.5
      )
   )
 )

 (setq d (/ X (* n1 k0)))

 (setq
   q1 (/ (* n1 (/ (sin footprint-latitude) (cos footprint-latitude)))
  r1
      )
 )

 (setq q2 (/ (* d d) 2))

 (setq	q3 (/ (* (- (+ 5
	       (* 3 t1)
	       (* 10 c1)
	    )
	    (* 4 c1 c1)
	    (* 9 eprime2)
	 )
	 (expt d 4)
      )
      24
   )
 )

 (setq	q4 (/ (* (- (+ 61
	       (* 90 t1)
	       (* 298 c1)
	       (* 45 t1 t1)
	    )
	    (* 3 c1 c1)
	    (* 252 eprime2)
	 )
	 (expt d 6)
      )
      720
   )
 )

 (setq q6 (/ (* (+ 1 (* 2 t1) c1) (expt d 3)) 6))

 (setq	q7 (/ (*
	(+ (- (+ (- 5 (* 2 c1)) (* 28 t1)) (* 3 c1 c1))
	   (* 8 eprime2)
	   (* 24 t1 t1)
	)
	(expt d 5)
      )
      120
   )
 )

 (setq zone-cm (- (* 6.0 lonzone) 183.0))

 (setq lat (- footprint-latitude (* q1 (+ (- q2 q3) q4))))

 (setq latitude (* (/ 180 pi) lat))
 (if (> latitude 90.0)
   (setq latitude 90.0)
   (setq latitude latitude)
 )

 (setq latdeg (fix latitude))
 (setq latmins (* (- latitude (fix latitude)) 60))
 (setq latsecs (* (- latmins (fix latmins)) 60))

 (setq long (/ (+ (- d q6) q7) (cos footprint-latitude)))

 (setq longr (* (/ 180 pi) long))

 (setq longitude (- zone-cm longr))

 (if (< longitude 0.0)
   (setq lonhem "W")
   (setq lonhem "E")
 )

 (if (< longitude 0.0)
   (setq longitude (* -1 longitude))
   (setq longitude longitude)
 )

 (setq londeg (fix longitude))
 (setq lonmins (* (- longitude (fix longitude)) 60))
 (setq lonsecs (* (- lonmins (fix lonmins)) 60))

 (princ (strcat "\n Latitude : "
	 (itoa latdeg)
	 "°"
	 (itoa (fix latmins))
	 "'"
	 (rtos latsecs 2 2)
	 "''"
	 Hem
 )
 )
 (princ (strcat "\n Longitude: "
	 (itoa londeg)
	 "°"
	 (itoa (fix lonmins))
	 "'"
	 (rtos lonsecs 2 2)
	 "''"
	 lonhem
 )
 )
 (princ)
)

but i want a lisp that could help me to solve my prob.

e.g. using this lisp we are getting latitude and longitude.

now from block 1 i want A°B'C"N get replaced with longitude and E°F'G"E get replaced with latitude.

which gives the result we i have given in block2.

 

thanks a lot

Block2.dwg

Block1.dwg

Link to comment
Share on other sites

sorry i forgot to mention that i have used Zone - 42 and Hemisphere-N in block 2 drawing

Link to comment
Share on other sites

Just insert the block at the co-ord as part of your lisp then it will ask for the two attributes automatically just need a simple extra line

 

(command "Insert" "Dwg1" pt 1 1 0 Lat long)

Change 
(princ (strcat "\n Latitude to (setq Lat (strcat "Latitude 

Link to comment
Share on other sites

Thanks a lot BIGAL

 

i have changed my lisp as per your suggestion and my new modifies lisp is now

(defun C:1 ()

 (setq lonzone (getint "\n Enter Zone:"))

 (initget "N S")
 (setq Hem (getkword "\n Enter the Hemisphere (S/N):"))

 (setq Pnt (Getpoint "\n Specify Point:"))

 (setq Xval (car Pnt))

 (setq Yval (car (cdr Pnt)))

 (if (= Hem "S")
   (setq Y (- 10000000 Yval))
   (setq Y Yval)
 )

 (if (and (or (= Hem "S") (= Hem "N")) (= Yval 0.0))
   (progn
     (setq Y Yval)
     (setq Hem "Equator")
   )
   (progn
     (setq Y Y)
     (Setq Hem Hem)
   )
 )


 (setq b 6356752.3142)

 (setq a 6378137.0)

 (setq X (- 500000.0 Xval))

 (setq e (sqrt (- 1.0 (expt (/ b a) 2.0))))

 (setq k0 0.9996)

 (setq meridional-arc (/ Y k0))

 (setq	mu (/ meridional-arc
      (* a
	 (- 1
	    (/ (expt e 2) 4)
	    (/ (* 3 (expt e 4)) 64)
	    (/ (* 5 (expt e 6)) 256)
	 )
      )
   )
 )

 (setq	e1 (/ (- 1 (expt (- 1 (expt e 2)) 0.5))
      (+ 1 (expt (- 1 (expt e 2)) 0.5))
   )
 )

 (setq j1 (- (/ (* 3 e1) 2) (/ (* 27 (expt e1 3)) 32)))

 (setq j2 (- (/ (* 21 (expt e1 2)) 16) (/ (* 55 (expt e1 4)) 32)))

 (setq j3 (/ (* 151 (expt e1 3)) 96))

 (setq j4 (/ (* 1097 (expt e1 4)) 512))

 (setq	footprint-latitude
 (+ mu
    (* j1 (sin (* 2.0 mu)))
    (* j2 (sin (* 4.0 mu)))
    (* j3 (sin (* 6.0 mu)))
    (* j4 (sin (* 8.0 mu)))
 )
 )

 (setq eprime2 (/ (* e e) (- 1.0 (* e e))))

 (setq c1 (* eprime2 (expt (cos footprint-latitude) 2)))

 (setq	t1 (expt (/ (sin footprint-latitude) (cos footprint-latitude))
	 2
   )
 )

 (setq	r1 (/ (* a (- 1 (expt e 2)))
      (expt (- 1
	       (* (expt e 2)
		  (expt (sin footprint-latitude) 2)
	       )
	    )
	    1.5
      )
   )
 )

 (setq	n1 (/ a
      (expt (- 1
	       (* e
		  e
		  (sin footprint-latitude)
		  (sin footprint-latitude)
	       )
	    )
	    0.5
      )
   )
 )

 (setq d (/ X (* n1 k0)))

 (setq
   q1 (/ (* n1 (/ (sin footprint-latitude) (cos footprint-latitude)))
  r1
      )
 )

 (setq q2 (/ (* d d) 2))

 (setq	q3 (/ (* (- (+ 5
	       (* 3 t1)
	       (* 10 c1)
	    )
	    (* 4 c1 c1)
	    (* 9 eprime2)
	 )
	 (expt d 4)
      )
      24
   )
 )

 (setq	q4 (/ (* (- (+ 61
	       (* 90 t1)
	       (* 298 c1)
	       (* 45 t1 t1)
	    )
	    (* 3 c1 c1)
	    (* 252 eprime2)
	 )
	 (expt d 6)
      )
      720
   )
 )

 (setq q6 (/ (* (+ 1 (* 2 t1) c1) (expt d 3)) 6))

 (setq	q7 (/ (*
	(+ (- (+ (- 5 (* 2 c1)) (* 28 t1)) (* 3 c1 c1))
	   (* 8 eprime2)
	   (* 24 t1 t1)
	)
	(expt d 5)
      )
      120
   )
 )

 (setq zone-cm (- (* 6.0 lonzone) 183.0))

 (setq lat (- footprint-latitude (* q1 (+ (- q2 q3) q4))))

 (setq latitude (* (/ 180 pi) lat))
 (if (> latitude 90.0)
   (setq latitude 90.0)
   (setq latitude latitude)
 )

 (setq latdeg (fix latitude))
 (setq latmins (* (- latitude (fix latitude)) 60))
 (setq latsecs (* (- latmins (fix latmins)) 60))

 (setq long (/ (+ (- d q6) q7) (cos footprint-latitude)))

 (setq longr (* (/ 180 pi) long))

 (setq longitude (- zone-cm longr))

 (if (< longitude 0.0)
   (setq lonhem "W")
   (setq lonhem "E")
 )

 (if (< longitude 0.0)
   (setq longitude (* -1 longitude))
   (setq longitude longitude)
 )

 (setq londeg (fix longitude))
 (setq lonmins (* (- longitude (fix longitude)) 60))
 (setq lonsecs (* (- lonmins (fix lonmins)) 60))
 (setq Lat (strcat "Latitude" (itoa latdeg)
	 "°"
	 (itoa (fix latmins))
	 "'"
	 (rtos latsecs 2 2)
	 "''"
	 Hem
 )
 )
 (setq long (strcat "Longitude" (itoa londeg)
	 "°"
	 (itoa (fix lonmins))
	 "'"
	 (rtos lonsecs 2 2)
	 "''"
	 lonhem
 )
 )
(command "Insert" "test" pnt 1 1 0 Lat long)
 (princ)
)

 

but it is giving error when i am going to work on it with attribute block which i have attached.

 

the erroe it is showing is

Command: 1
Enter Zone:42
Enter the Hemisphere (S/N):N
Specify Point:Unknown command "LATITUDE20°55'23.23''N".  Press F1 for help.
Unknown command "LONGITUDE71°31'26.21''E".  Press F1 for help.

 

Is anything wrong in that lisp that it is showing error

Block1.dwg

Link to comment
Share on other sites

Seems that the block you are using in code (test) doen't contains the two expected attributes - if you don't know how to create them, just check this tutorial. Or the ATTREQ system variable is set to 0 instead of 1.

Link to comment
Share on other sites

thanks Msasu

 

that tutorial helped me lot to learn new things. now i have created new attribute block but still showing same error with that lisp.

Block1.dwg

Link to comment
Share on other sites

Seems that you didn't fixed the state of ATTREQ system variable - this is set to 0 in the example drawing you attached. Therefore, when instert the block trough AutoLISP the interpreter doesn't expect the values of the attributes. Set the said variable to 1 and it should works as expected.

Link to comment
Share on other sites

I have gone as per you said and it is working comfortably now

 

Thanks a lot Msasu & BIGAL

 

but i need one more thing wherever i will place that block it should get closest round off position

i.e. if i placed it on 762474.5943,2315668.1052, it will give latitude- 77°31'25.01''E and longitude - 20°55'22.05''N

but i want to get placed to latitude- 77°31'25.00''E and longitude - 20°55'22.00''N

means closest position where i'll get .00 decimal

 

Is there any way to make it possible

Link to comment
Share on other sites

You can play with rounding errors been a while simple example is multiply a number by 100 take the integer then divide again 100 this chops last 2 numbers. with lats and long need a bit of experiment or else just chop seconds in string answer but do you round up?

Link to comment
Share on other sites

being newbie i really don't have that much idea how to edit this codes, can you please show me once

Link to comment
Share on other sites

i tried to merge one different lisp (which converts lat long to X Y coords) with my previous lisp to get round off values of lat long but it is showing some error

 

new modified lisp is as follows

(defun C:1 ()

 (setq lonzone (getint "\n Enter Zone:"))

 (initget "N S")
 (setq Hem (getkword "\n Enter the Hemisphere (S/N):"))

 (setq Pnt (Getpoint "\n Specify Point:"))

 (setq Xval (car Pnt))

 (setq Yval (car (cdr Pnt)))

 (if (= Hem "S")
   (setq Y (- 10000000 Yval))
   (setq Y Yval)
 )

 (if (and (or (= Hem "S") (= Hem "N")) (= Yval 0.0))
   (progn
     (setq Y Yval)
     (setq Hem "Equator")
   )
   (progn
     (setq Y Y)
     (Setq Hem Hem)
   )
 )


 (setq b 6356752.3142)

 (setq a 6378137.0)

 (setq X (- 500000.0 Xval))

 (setq e (sqrt (- 1.0 (expt (/ b a) 2.0))))

 (setq k0 0.9996)

 (setq meridional-arc (/ Y k0))

 (setq	mu (/ meridional-arc
      (* a
	 (- 1
	    (/ (expt e 2) 4)
	    (/ (* 3 (expt e 4)) 64)
	    (/ (* 5 (expt e 6)) 256)
	 )
      )
   )
 )

 (setq	e1 (/ (- 1 (expt (- 1 (expt e 2)) 0.5))
      (+ 1 (expt (- 1 (expt e 2)) 0.5))
   )
 )

 (setq j1 (- (/ (* 3 e1) 2) (/ (* 27 (expt e1 3)) 32)))

 (setq j2 (- (/ (* 21 (expt e1 2)) 16) (/ (* 55 (expt e1 4)) 32)))

 (setq j3 (/ (* 151 (expt e1 3)) 96))

 (setq j4 (/ (* 1097 (expt e1 4)) 512))

 (setq	footprint-latitude
 (+ mu
    (* j1 (sin (* 2.0 mu)))
    (* j2 (sin (* 4.0 mu)))
    (* j3 (sin (* 6.0 mu)))
    (* j4 (sin (* 8.0 mu)))
 )
 )

 (setq eprime2 (/ (* e e) (- 1.0 (* e e))))

 (setq c1 (* eprime2 (expt (cos footprint-latitude) 2)))

 (setq	t1 (expt (/ (sin footprint-latitude) (cos footprint-latitude))
	 2
   )
 )

 (setq	r1 (/ (* a (- 1 (expt e 2)))
      (expt (- 1
	       (* (expt e 2)
		  (expt (sin footprint-latitude) 2)
	       )
	    )
	    1.5
      )
   )
 )

 (setq	n1 (/ a
      (expt (- 1
	       (* e
		  e
		  (sin footprint-latitude)
		  (sin footprint-latitude)
	       )
	    )
	    0.5
      )
   )
 )

 (setq d (/ X (* n1 k0)))

 (setq
   q1 (/ (* n1 (/ (sin footprint-latitude) (cos footprint-latitude)))
  r1
      )
 )

 (setq q2 (/ (* d d) 2))

 (setq	q3 (/ (* (- (+ 5
	       (* 3 t1)
	       (* 10 c1)
	    )
	    (* 4 c1 c1)
	    (* 9 eprime2)
	 )
	 (expt d 4)
      )
      24
   )
 )

 (setq	q4 (/ (* (- (+ 61
	       (* 90 t1)
	       (* 298 c1)
	       (* 45 t1 t1)
	    )
	    (* 3 c1 c1)
	    (* 252 eprime2)
	 )
	 (expt d 6)
      )
      720
   )
 )

 (setq q6 (/ (* (+ 1 (* 2 t1) c1) (expt d 3)) 6))

 (setq	q7 (/ (*
	(+ (- (+ (- 5 (* 2 c1)) (* 28 t1)) (* 3 c1 c1))
	   (* 8 eprime2)
	   (* 24 t1 t1)
	)
	(expt d 5)
      )
      120
   )
 )

 (setq zone-cm (- (* 6.0 lonzone) 183.0))

 (setq lat (- footprint-latitude (* q1 (+ (- q2 q3) q4))))

 (setq latitude (* (/ 180 pi) lat))
 (if (> latitude 90.0)
   (setq latitude 90.0)
   (setq latitude latitude)
 )

 (setq latdeg (fix latitude))
 (setq latmins (* (- latitude (fix latitude)) 60))
 (setq latsecs (* (- latmins (fix latmins)) 60))

 (setq long (/ (+ (- d q6) q7) (cos footprint-latitude)))

 (setq longr (* (/ 180 pi) long))

 (setq longitude (- zone-cm longr))

 (if (< longitude 0.0)
   (setq lonhem "W")
   (setq lonhem "E")
 )

 (if (< longitude 0.0)
   (setq longitude (* -1 longitude))
   (setq longitude longitude)
 )

 (setq londeg (fix longitude))
 (setq lonmins (* (- longitude (fix longitude)) 60))
 (setq lonsecs (* (- lonmins (fix lonmins)) 60))
	(setq Latitude (strcat (itoa latdeg)
	 "°"
	 (itoa (fix latmins))
	 "'"
	 (rtos latsecs 2 2)
	 "''"
	 Hem
 )
 )
  (setq longitude (strcat (itoa londeg)
	 "°"
	 (itoa (fix lonmins))
	 "'"
	 (rtos lonsecs 2 2)
	 "''"
	 lonhem
 )
 )

 (setq latd (itoa latdeg))
 (setq latm (itoa (fix latmins)))
 (setq lats (itoa (fix latsecs)))
 (setq longd (itoa londeg))
 (setq longm (itoa (fix lonmins)))
 (setq longs (itoa (fix lonsecs)))
 (setq lon (float (+ longd (/ longm 60) (/ longs 3600))))
 (setq lat (float (+ latd (/ latm 60) (/ lats 3600))))
 (setq	zon (itoa lonzone))

 (setq a# 6378137.0)
 (setq b 6356752.3142)
 (setq n# (/ (- a# b) (+ a# b)))
 (setq eccSquared (/ (- (expt a# 2) (expt b 2)) (expt a# 2)))
 (setq ecc2 (- (/ (expt a# 2) (expt b 2)) 1))
 (setq eccPrimeSquared (/ eccSquared (- 1.0 eccSquared)))
 (setq k0 0.9996)

 (setq TRIG (/ PI 180))
 (setq phi (* lat TRIG))
 (setq lam (* lon TRIG))

 (setq e (sqrt (- 1 (/ (expt b 2) (expt a# 2)))))


 (if (= zon nil)
   (setq zone (fix (+ 31 (/ lon 6))))
   (setq zone zon)
 )


 (setq lono (+ (- (* (- zone 1.0) 6) 180) 3))
 (setq lamo (* TRIG lono))

 (setq N (/ a# (sqrt (- 1.0 (* eccSquared (sin phi) (sin phi))))))
 (setq TT (* (/ (sin phi) (cos phi)) (/ (sin phi) (cos phi))))
 (setq C (* eccPrimeSquared (cos phi) (cos phi)))
 (setq A (* (cos phi) (- lam lamo)))

 (setq	meridional-arc
 (* a#
    (- (+ (- (*	(- (- 1 (/ (expt e 2) 4))
		   (* 3 (/ (expt e 4) 64))
		   (* 5 (/ (expt e 6) 256))
		)
		phi
	     )
	     (*	(+ (/ (* 3 (expt e 2)) 
		   (/ (* 3 (expt e 4)) 32)
		   (/ (* 45 (expt e 6)) 1024)
		)
		(sin (* 2 phi))
	     )
	  )
	  (* (+	(/ (* 15 (expt e 4)) 256)
		(/ (* 45 (expt e 6)) 1024)
	     )
	     (sin (* 4 phi))
	  )
       )
       (* (/ (* 35 (expt e 6)) 3072) (sin (* 6 phi)))
    )
 )
 )






 (setq	X
 (+ (* k0
       N
       (+ A
	  (* (+ (- 1.0 TT) C) A A A (/ 1.0 6.0))
	  (* (-	(+ (- 5.0 (* 18.0 TT)) (* TT TT) (* 72.0 C))
		(* 58.0 eccPrimeSquared)
	     )
	     A
	     A
	     A
	     A
	     A
	     (/ 1.0 120.0)
	  )
       )
    )
    500000.0
 )
 )
 (setq	RawY
 (* k0
    (+ meridional-arc
       (* N
	  (/ (sin phi) (cos phi))
	  (+ (* A A (/ 1.0 2.0))
	     (*	(+ (- 5.0 TT)
		   (* 9.0 C)
		   (* 4.0 C C)
		)
		A
		A
		A
		A
		(/ 1.0 24.0)
	     )
	     (*	(- (+ (- 61.0 (* 58.0 TT))
		      (* TT TT)
		      (* 600.0 C)
		   )
		   (* 330.0 eccPrimeSquared)
		)
		A
		A
		A
		A
		A
		A
		(/ 1.0 720.0)
	     )
	  )
       )
    )
 )
 )

 (if (< RawY 0)
   (Setq Y (+ 10000000 RawY))
   (Setq Y RawY)
 )
(if (< lat 0)
   (setq Hem "S")
   (setq Hem "N"))
 (if (< lon 0)
   (setq HHem "W")
   (setq HHem "E"))


 (setq utmx (rtos X 2 3))
 (setq utmy (rtos Y 2 3))

 (setq NWpnt ((Itoa utmx) "," (itoa utmy)))

(command "Insert" "NEInt" NWpnt 1 1 0 Latitude longitude)
 )

 

and i have attached block too

 

please go through my lisp and let me know

 

 

Thanks a lot

NEInt.dwg

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