satishrajdev Posted February 21, 2013 Share Posted February 21, 2013 Hi guys, i am trying to update my code which is as follows, which i am using to get X,Y,Lat,Long,Bearing & Distance of attribute block from center location : (defun c:1 (/ file dta p i) (vl-load-com) ;;; Creat CSV File (if (and (setq file (open (getfiled "specify output file" "c:/" "csv" 1) "w")) (setq dta (ssget '((0 . "INSERT") (66 . 1)))) (setq tag (getstring "\nSpecify Tag String: ")) (not (eq "" tag))) (progn (write-line "Sr No,Easting (mE),Northing (mN),Latitude (N),Longitude (E),Sonar Conctact Dimension,Bearing,Distance" file) (princ " Initial number of point ID <") (princ no) (princ ">:") (setq nno (getint)) (if (= nno nil) (terpri) (setq no nno) ) (setq no (- no 1)) (setq factp (getpoint "\n Pick Location Center: ")) ;;; Geographical Datum Input (setq lonzone (getint "\n Enter Zone:")) (initget "N S") (setq Hem (getkword "\n Enter the Hemisphere (S/N):")) (terpri) (princ "Sr No Easting Northing Latitude Longitude Distance Bearing") (repeat (setq i (sslength dta)) (setq eb (entget (ssname dta (setq i (1- i))))) (setq obj (vlax-ename->vla-object (ssname dta (setq i (1- i))))) (setq p (cdr (assoc 10 eb))) (setq actp (list (car p) (cadr p) 0)) (setq Xval (car p)) (setq Yval (car (cdr p))) (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 latf (strcat (itoa latdeg) "°" (itoa (fix latmins)) "'" (rtos latsecs 2 2) "''" Hem ) ) (setq longf (strcat (itoa londeg) "°" (itoa (fix lonmins)) "'" (rtos lonsecs 2 2) "''" lonhem ) ) ;;; Attribute function (foreach a (vlax-invoke obj 'getattributes) (setq tag_val (vlax-get a 'TagString)) (setq att_val (vlax-get a 'TextString)) (setq atbv (strcat tag_val "-" att_val))) ;;; Bearing & Distance Details (setq angtype (getvar "AUNITS")) ;;; Get current user Units (setq oldir (getvar "ANGDIR")) ;;;; Get current user Direction (setq sdist (rtos (distance factp actp)2 1)) (setq mang (angle factp actp)) ;;; Get Angle in Radians (cond ((= angtype 0) (setq mang (angtos mang 0 0))) ;;; <--- From here ((= angtype 1) (setq mang (angtos mang 1 0))) ((= angtype 2) (setq mang (angtos mang 2 0))) ((= angtype 3) (setq mang (angtos mang 3 0))) ((= angtype 4) (setq mang (angtos mang 4 0)))) ;;; <---To here, Set angle to user Unit settings and convert to string ;;; Princ Function (setq no (+ no 1)) (terpri) (princ " ") (princ no) (princ ". ") (princ (rtos (car p) 2 3)) (princ " ") (princ (rtos (cadr p) 2 3)) (princ " ") (princ latf) (princ " ") (princ longf) (princ " ") (princ (strcat sdist "m")) (princ " ") (princ (strcat mang "°")) (princ " ") (princ atbv) ;;;Output Details of CSV file (write-line (strcat (rtos no 2 1) "," (rtos (car p) 2 3) "," (rtos (cadr p) 2 3) "," latf "," longf "," atbv "," (strcat sdist "m") "," (strcat mang "°") ) file ) ) (close file) ) ) (Princ) ) but there is a prob with the attribute value it is giving ; error: bad argument type: lentityp nil error... the problem is only with attribute value, plz check my code & provide solution for that thankx a lot Quote Link to comment Share on other sites More sharing options...
MSasu Posted February 21, 2013 Share Posted February 21, 2013 To allow someone test your code excerpt you should provide also an example file; other is too difficult to follow its logic. Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted February 21, 2013 Author Share Posted February 21, 2013 I m sorry for that MSasu.... example file i have attached below, in that when i am selecting all attributes it giving following error:- Command: 1 Select objects: Specify opposite corner: 8 found Select objects: Specify Tag String: sonar Initial number of point ID <5>:1 Pick Location Center: Enter Zone:42 Enter the Hemisphere (S/N):n Sr No Easting Northing Latitude Longitude Distance Bearing 1. 704125.490 2113759.381 19°6'23.93''N 70°56'25.38''E 846.5m 348° SONAR-2.3m X 0.7m X nmh (SC-03-FSC) 2. 704115.210 2113134.511 19°6'3.61''N 70°56'24.79''E 276.9m 317° SONAR-1.5m Long (SC-05-LSC) 3. 703437.721 2112956.323 19°5'58.06''N 70°56'1.55''E 866.6m 272° SONAR-1.6m X 0.6m X nmh (SC-07-FSC) 4. 704953.995 2112852.453 19°5'54.14''N 70°56'53.37''E 654.9m 97° SONAR-2.6m Long (SC-10-LSC); error: bad argument type: lentityp nil (; error: bad argument type: lentityp nil) is only my prob Sonar contact test.dwg Quote Link to comment Share on other sites More sharing options...
MSasu Posted February 21, 2013 Share Posted February 21, 2013 Please pay attention that you are decreasing the selection set index parser faster that should - with 2 at each parse: (repeat (setq i (sslength dta)) (setq eb (entget (ssname dta [color=red](setq i (1- i))[/color]))) (setq obj (vlax-ename->vla-object (ssname dta [color=red](setq i (1- i))[/color]))) For this reason the variable i will become negative. I believe that is should be instead: (repeat (setq i (sslength dta)) (setq eb (entget (ssname [color=black]dta (setq i (1- i))[/color]))) (setq obj (vlax-ename->vla-object (ssname dta [color=red][b]i[/b][/color]))) or: (repeat (setq i (sslength dta)) (setq eb (entget [color=red](setq theEntity[/color] (ssname dta (setq i (1- i)))[color=red])[/color])) (setq obj (vlax-ename->vla-object [color=red]theEntity[/color])) Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted February 21, 2013 Author Share Posted February 21, 2013 I understood it completely.... it will help me in future for coding thankx a lot MSasu the lisp is working perfectly for me now..... Quote Link to comment Share on other sites More sharing options...
MSasu Posted February 21, 2013 Share Posted February 21, 2013 Sound very good! Glad I could be of help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.