; error: bad argument type: 2D/3D point: nil

; error: bad argument type: 2D/3D point: nil

buchistyle
Participant Participant
2,295 Views
15 Replies
Message 1 of 16

; error: bad argument type: 2D/3D point: nil

buchistyle
Participant
Participant

Hello, please I need help. I get this error

 

; error: bad argument type: 2D/3D point: nil

 

when trying to run this

 

Command: (load "C:/Users/Look PC 1/Desktop/Dimdist")

The contents of the Dimdist file are supposed to allow me automatically display the bearings and distances of lines. It runs thus:

 

(setq ang (vl-string-subst "%%d" "d" (angtos (angle p1 p2))))
(setq dist (strcat (rtos (/ (distance p1 p2) 12) 2) "'"))

(defun c:brg69(/ om dsc an ent p1 p2 p3 ang dist lf1 lf2 f1 f2
mtxt dist1 dist2 ht lp1 lp2 lp3 lp4)
(setq dsc (getvar "dimscale"))
(setq ht (* 0.25 dsc)) ;;; <<< - sets text size of note
(setq an (getvar "aunits"))
(setq ln (getvar "lunits"))
(setq anp (getvar "auprec"))
(setq lnp (getvar "luprec"))
(setvar "lunits" 4)
(setvar "luprec" 2)
(setvar "aunits" 4)
(setvar "auprec" 6)
(setq ent (entget (car (entsel "\nSelect Line: "))))
(setq p1 (cdr (assoc 10 ent)))
(setq p2 (cdr (assoc 11 ent)))
(setq ang (angtos (angle p1 p2)))
(setq dist (rtos (distance p1 p2) 2))
(setq mtxt (strcat dist "\\P" ang))
(setq dist1 (* dsc 2))
(setq dist2 (* dsc 1))
(setq lp1 (getpoint"\nSelect First Leader Point or Midpoint of Line: "))
(setq lp2 (getpoint lp1 "\nSelect Second Leader Point or Midpoint of Line: "))
(command"line" lp1 lp2 "")
(setq lp3 (getpoint lp2 "\nSelect Leader Leg or Text Direction: "))
(command "erase" "l" "")
(setq lp4 (polar lp2 (angle lp2 lp3) dist1))
(setq p3 (polar lp2 (angle lp2 lp3) dist2))
(command"leader" lp1 lp2 lp4 "" "" "n" "")
(setvar "aunits" 0)
(setq lf1 (car lp2))
(setq lf2 (car lp3))
(setq f1 (cadr lp2))
(setq f2 (cadr lp3))
(command"mtext" p3 "r" (atof(angtos (angle p1 p2))) "h" ht "j" "mc" p3 mtxt "")
(if
(or
(> f1 f2)
(> lf1 lf2)
(/= f1 f2)
(= lf1 lf2)
)
(command "rotate" "l" "" p3 "180")
)
(if (< f1 f2)(command"undo" "1"))
(setvar "aunits" an)
(setvar "auprec" anp)
(setvar "lunits" ln)
(setvar "luprec" lnp)
(princ)
)

 

I got the programme from the internet. I know absolutely nothing of AutoLISPing. Please help. Thanks in advance.

0 Likes
Accepted solutions (4)
2,296 Views
15 Replies
Replies (15)
Message 2 of 16

Kent1Cooper
Consultant
Consultant

It looks like the first two lines are revised versions to set the variables as text strings in better format for the purpose.  They should not be there at the beginning, where the first line calls for a variable that has not had a value set in it yet [that's the source of the error message].  Try taking those first two lines and moving them down to replace these two lines later:


(setq ang (angtos (angle p1 p2)))
(setq dist (rtos (distance p1 p2) 2))

Kent Cooper, AIA
0 Likes
Message 3 of 16

calderg1000
Mentor
Mentor

Regards @buchistyle 

For the routine to work, you only have to remove the first 2 lines, otherwise you can also comment them, preceding the semicolons, as in the attached view.

 

;;;(setq ang (vl-string-subst "%%d" "d" (angtos (angle p1 p2))))
;;;(setq dist (strcat (rtos (/ (distance p1 p2) 12) 2) "'"))

 

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 4 of 16

buchistyle
Participant
Participant

Okay thanks a lot guys @Kent1Cooper@calderg1000. That segment was actually from another contributor on the site I got the code from. He said to add it at the beginning or end of the code. Any way, I have removed it but now the error message is:

 

; error: bad argument type: 2D/3D point: nil

0 Likes
Message 5 of 16

Kent1Cooper
Consultant
Consultant

@calderg1000 wrote:

Regards @buchistyle 

.... you only have to remove the first 2 lines, ... you can also comment them, ....


That depends on what kind of result you want in the text content:

Kent1Cooper_0-1658317828498.png

 

Kent Cooper, AIA
0 Likes
Message 6 of 16

Kent1Cooper
Consultant
Consultant

@buchistyle wrote:

.... I have removed it but now the error message is:

; error: bad argument type: 2D/3D point: nil


Are you selecting a Line object specifically?  You would get that kind of message if you select a Polyline, because the 'p2' variable will be nil, since there is no 11-code entry in entity data for a Polyline, as there is for the endpoint of a Line.

 

ALSO:  How far does it get before the error?  If it happens after the initial selection, the above could be the issue.  If it gets to prompting for the Leader points, probably not.

Kent Cooper, AIA
0 Likes
Message 7 of 16

calderg1000
Mentor
Mentor

Dear @buchistyle 

I tried the routine and for me it works fine. for the result, I prefer to use multileader, but we don't know how you require the result. Apparently the leader is too much, since the result is read aligned with the selected line.
Do not forget that this routine is valid to select only "LINES".
If possible, attach your file for review and a sample of how you require the result.


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 8 of 16

Sea-Haven
Mentor
Mentor

A version 2 would check for is it a Line or Pline if pline repeat for all segments.

 

There is other BRG DIST routines out there do you need the leader option ? Again version 3 aligned to line or a leader. CIV3D built in feature to label lines.

 

 

Message 9 of 16

buchistyle
Participant
Participant

Sorry guys for late response.

 

Actually what I want to achieve is simply to be able to see the bearing and distance of red lines representing land/property boundaries. What I currently do is draw the lines on model space e.g.:

 

MODEL SPACE.jpg

Then I switch into layout/paper space to do the the annotation. Example:

 

Paper Space.jpg

I have to switch back and forth between the model and paper spaces to get the bearing and distance properties of the lines using List command before typing them in along the lines. This can be time consuming and it would be great if I could see the info right on the paper space. So I may not really have any preferences as per leader or no leader or multileader etc. @calderg1000 the programme hasn't worked on my system so I don't even know what the output is like 🙂

 

@Kent1Cooper, in reply to your question:

...How far does it get before the error? ...

 

My answer: It doesn't get anywhere. I hit the run command and next thing the error appears.  As shown below.

 

Error.jpg

 

@Sea-Haven, I might not have access to civil3d all the time. So I prefer a routine that would work on plain ACAD.

 

Thanks guys.

 

0 Likes
Message 10 of 16

buchistyle
Participant
Participant

Uh oh... Seems I really didn't remove the first two lines as I thought. Now I have and I am getting this:

 

Whatnext.jpg

 

So what am I to do now? Am I supposed to enter something? Press a key or what?

0 Likes
Message 11 of 16

Kent1Cooper
Consultant
Consultant
Accepted solution

@buchistyle wrote:

Uh oh... Seems I really didn't remove the first two lines as I thought. Now I have and I am getting this:

So what am I to do now? Am I supposed to enter something? Press a key or what?


Type in the command name BRG69 [not case-sensitive] -- the part immediately after the C: in the (defun C:...  line of code.  It's just showing you the name of the command that was defined in the file you loaded.  Loading a file does not automatically run the command defined in it -- after all, one file can contain multiple command and/or function definitions, in which case which one(s) should it run?

 

[You can build it to run the command automatically upon loading if you want, by adding another line:

(C:BRG69)

at the end of the file.]

Kent Cooper, AIA
Message 12 of 16

CADaSchtroumpf
Advisor
Advisor
Accepted solution

You can try this!

At the end of procedure you can use the command "CHSPACE" for transfert the mtext to paper space.

(vl-load-com)
(defun c:brg69 ( / l_var js htx AcDoc Space ss nw_style n obj ename pr dist_start dist_end pt_start pt_end seg_len alpha val_txt dim_txt nw_obj)
  (setq l_var (mapcar 'getvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS")))
  (mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") '(4 3 2 2))
  (princ "\nSelect polylines or lines.")
  (while (null (setq js (ssget '((0 . "LWPOLYLINE,LINE")))))
    (princ "\nSelection is empty or not are LWPOLYLINE,LINE!")
  )
  (initget 6)
  (setq htx (getdist (getvar "VIEWCTR") (strcat "\nSpecify text height <" (rtos (getvar "TEXTSIZE")) ">: ")))
  (if htx (setvar "TEXTSIZE" htx))
  (setq
    AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    Space
    (if (= 1 (getvar "CVPORT"))
      (vla-get-PaperSpace AcDoc)
      (vla-get-ModelSpace AcDoc)
    )
    ss (ssadd)
  )
  (vla-startundomark AcDoc)
  (cond
    ((null (tblsearch "LAYER" "DIMENSIONS"))
      (vlax-put (vla-add (vla-get-layers AcDoc) "DIMENSIONS") 'color 7)
    )
  )
  (cond
    ((null (tblsearch "STYLE" "LABEL_ARIAL"))
      (setq nw_style (vla-add (vla-get-textstyles AcDoc) "LABEL_ARIAL"))
      (mapcar
        '(lambda (pr val)
          (vlax-put nw_style pr val)
        )
        (list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag)
        (list (strcat (getenv "windir") "\\fonts\\arial.ttf") 0.0 0.0 1.0 0.0)
      )
    )
  )
  (repeat (setq n (sslength js))
    (setq
      obj (ssname js (setq n (1- n)))
      ename (vlax-ename->vla-object obj)
      pr -1
    )
    (cond
      ((eq (cdr (assoc 0 (entget obj))) "LWPOLYLINE")
        (repeat (fix (vlax-curve-getEndParam ename))
          (setq
            dist_start (vlax-curve-GetDistAtParam ename (setq pr (1+ pr)))
            dist_end (vlax-curve-GetDistAtParam ename (1+ pr))
            pt_start (vlax-curve-GetPointAtParam ename pr)
            pt_end (vlax-curve-GetPointAtParam ename (1+ pr))
            seg_len (- dist_end dist_start)
            alpha (angle (trans pt_start 0 1) (trans pt_end 0 1))
            val_txt (vl-string-subst "%%d" "d"(strcat (angtos alpha) "\\P " (rtos seg_len)))
            dim_txt (textbox (list (cons 1 val_txt)))
          )
          (if (and (> alpha (* pi 0.5)) (< alpha (* pi 1.5))) (setq alpha (+ alpha pi)))
          (if (> (distance (car dim_txt) (cadr dim_txt)) seg_len)
            (setq val_txt (vl-string-subst "E \\P" "E " val_txt))
          )
          (setq nw_obj
            (vla-addMtext Space
              (vlax-3d-point (setq pt (vlax-curve-GetPointAtParam ename (+ 0.5 pr))))
              0.0
              val_txt
            )
          )
          (mapcar
            '(lambda (pr val)
              (vlax-put nw_obj pr val)
            )
            (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
            (list 5 (getvar "TEXTSIZE") 5 pt "LABEL_ARIAL" "DIMENSIONS" alpha)
          )
          (setq ss (ssadd (entlast) ss))
        )
      )
      (T
        (setq
          pt_start (vlax-curve-GetStartPoint ename)
          pt_end (vlax-curve-GetEndPoint ename)
          seg_len (distance pt_start pt_end)
          alpha (angle (trans pt_start 0 1) (trans pt_end 0 1))
          val_txt (vl-string-subst "%%d" "d"(strcat (angtos alpha) "\\P " (rtos seg_len)))
          dim_txt (textbox (list (cons 1 val_txt)))
        )
        (if (and (> alpha (* pi 0.5)) (< alpha (* pi 1.5))) (setq alpha (+ alpha pi)))
        (if (> (distance (car dim_txt) (cadr dim_txt)) seg_len)
          (setq val_txt (vl-string-subst "E \\P" "E " val_txt))
        )
        (setq nw_obj
          (vla-addMtext Space
            (vlax-3d-point (setq pt (mapcar '* (mapcar '+ (vlax-curve-GetStartPoint ename) (vlax-curve-GetEndPoint ename)) '(0.5 0.5 0.5))))
            0.0
            val_txt
          )
        )
        (mapcar
          '(lambda (pr val)
            (vlax-put nw_obj pr val)
          )
          (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
          (list 5 (getvar "TEXTSIZE") 5 pt "LABEL_ARIAL" "DIMENSIONS" alpha)
        )
        (setq ss (ssadd (entlast) ss))
      )
    )
  )
  (vla-endundomark AcDoc)
  (mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") l_var)
  (sssetfirst nil ss)
  (prin1)
)
Message 13 of 16

buchistyle
Participant
Participant

It works! Thanks a lot. Only I am disappointed in the results since they are in bearings rather than azimuths. The fault is mine somewhat. In Nigeria we always use the term bearing rather improperly to refer to azimuths. So when I searched for a routine to display the "bearings" and distances of lines I got what I asked for 😉

 

Please is there a way I can convert the bearings to azimuths? Also we use the metric system here and it would be great if I could have this routine working in that system. I don't have a problem with the distances (I guess AutoCAD just works with units and doesn't really know if they are feet or meters, right?) but setting the text size is in inches and I think that's archaic. 😀

0 Likes
Message 14 of 16

buchistyle
Participant
Participant

Oh my God! Do I love this? Absolutely.

 

Now I don't have to deal with all those requests for first leader leg, second leader leg, bla bla bla. Those requests come quite close to defeating the purpose of the automation. Thanks. Now I just have to deal with getting the directions in Azimuths rather then bearings properly so called.

0 Likes
Message 15 of 16

Kent1Cooper
Consultant
Consultant
Accepted solution

@buchistyle wrote:

.... getting the directions in Azimuths rather then bearings properly so called.


Read about the ANGBASE and ANGDIR System Variables to set the direction for 0° and the direction of positive progression of angles, and AUNITS to get the format of the angle text.

Kent Cooper, AIA
Message 16 of 16

buchistyle
Participant
Participant
Accepted solution

Okay. Thank you @Kent1Cooper  for pointing me in the right direction.

 

Thanks @CADaSchtroumpf for a great routine. I have adopted it with some minor modifications.

 

To get the azimuths and Deg/Min precision, I simply changed the values for the system variables AUNITS and AUPREC in the routine  to the appropriate values. It does pay to try reading the code even if it looks like gibberish initially.

 

Additionally, I got my UCS properly set to the correct Y = North, X = East orientation. I think this also contributed to meaningful outcomes eventually.

0 Likes