Jump to content

Recommended Posts

Posted

No problem, I might edit the code above just one more time later (couple of things that might be better)

Posted

..until then

 

one last "Thank You!"

  • 1 year later...
Posted

Hi Steven & ILoveMadoka,
Thank you both for this topic and the lisp, I desperately need this as I have a vast amount of civil 3d surface elevation callouts to explode and turn into normal Mleaders.
Did either of you ever get this message when using the lisp:
"; error: bad argument type: 2D/3D point: nil" or "; error: bad argument type: consp nil"?
Any ideas how to fix it? 

Posted

Normally means that for something that's been selected the LISP is looking for a point - insert point - and it can't find it.. but at which point I wonder?

 

Are you able to do some testing to help me work out where?

 

try this one with some temporary markers to show where the errors occur

 

;;Tested with MLeaders + arrows. Updated for other arrow types - not fully tested
(defun c:L2ml ( / thisdrawing fuzz ss acount MyEnt GetEnt EntType Dist1 Dist2 MLeaderPoint MyText TxtY Pt10 Pt11 Knee DistPt10 DistPt11 LLine)

;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-join-multiple-lines-together/td-p/4353198
;;Get furthest apart points
  (defun LM:furthestapart ( lst / di1 di2 pt1 rtn )
(princ "\n")(princ lst)
    (setq di1 0.0)
    (while (setq pt1 (car lst))
        (foreach pt2 (setq lst (cdr lst))
            (if (< di1 (setq di2 (distance pt1 pt2)))
                (setq di1 di2
                      rtn (list pt1 pt2)
                )
            )
        )
    )
(princ " Furthest Apart Works.")
    rtn
  )


;;Set Undo Mark
  (Setq thisdrawing (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark thisdrawing)

  (setq fuzz 0.001)                                   ; fuzz distance

  (if (setq ss (ssget '((0 . "*TEXT,*LINE,SOLID,INSERT"))) ) ; select leader parts
    (progn
      (setq acount 0)
      (while (< acount (sslength ss))                 ; Loop through selection set
        (setq MyEnt (ssname ss acount))               ; get entity definition
        (setq GetEnt (entget MyEnt))
        (setq EntType (cdr (assoc 0 GetEnt)))

(princ "\nEnt Type: ")(princ EntType)

        (cond                                         ; Condition for entity types

          ((= EntType "SOLID")                        ; Get arrow coordinates (standard)
(princ "\n Solid Arrow ")
            ;; work out arrow point
            (setq Dist1 (distance (cdr (assoc 11 GetEnt)) (cdr (assoc 10 GetEnt)) ))
            (setq Dist2 (distance (cdr (assoc 12 GetEnt)) (cdr (assoc 10 GetEnt)) ))
            (if (> Dist1 Dist2)                            ; Find point on longest edge
              (setq MLeaderPoint (cdr (assoc 11 GetEnt)) ) ; 1st point for MLEADER
              (setq MLeaderPoint (cdr (assoc 12 GetEnt)) ) ; 1st point for MLEADER
            ) ; end if
(princ MLeaderPoint)
          )   ; end cond Solid

          ((= Enttype "INSERT")                       ; Or for other arrow types
(princ "\n Insert Arrow ")
            (setq MLeaderPoint (cdr (assoc 10 GetEnt)) )
(princ MLeaderPoint)
          ) ; end Cond Insert

          ((or (= EntType "MTEXT")(= EntType "TEXT"))   ; get Text definitions
(princ "\n Text ")
            (if (= MyText nil)                          ; No text assessed
              (progn
                (setq MyText (cdr (assoc 1 GetEnt)))    ; Record the first text in the selection
                (setq TxtY (car (cdr (assoc 10 GetEnt))))  ; Record its Y coordinate
              ) ; end orogn
              (progn                                    ; 2nd or more text in selection set
                (if (< TxtY (car (cdr (assoc 10 GetEnt))) ) ; text positioned above or below previous text
                  (progn                                ; Suffix new text to original text
                    (setq MyText (strcat Mytext "\\P" (cdr (assoc 1 GetEnt)) ))
                  ) ; end progn
                  (progn                                ; Prefix new text, set a new upper Y coordinate
                    (setq MyText (strcat (cdr (assoc 1 GetEnt)) "\\P" Mytext ))
                    (setq TxtY (car (cdr (assoc 10 GetEnt))))
                  ) ; end progn
                ) ; end if
              ) ; end progn
            ) ; end if
(princ TxtY)
          ) ;end cond MText

          ((= EntType "LINE")                           ; Get line definitions
(princ "\nLine ")
            (setq Pt10 (cdr (assoc 10 GetEnt)) )        ; Line end A and end B
            (setq Pt11 (cdr (assoc 11 GetEnt)) )
            (if (equal (cdr Pt10) (cdr Pt11) fuzz)      ; For horizontal lines
              (progn
                (if (= Knee nil) (setq Knee (list Pt11 Pt10))) ; if knee point not specified
                (if (< (car Pt11)(car (car Knee)))(setq Knee (list Pt11 (cdr Knee)))) ; set extents
                (if (> (car Pt10)(cdr (cdr Knee)))(setq Knee (list (car Knee) Pt10)))
              )
              (progn                                   ; angled lines ;;need to work on this.
                (if (= LLine nil) (setq LLine (list Pt10 Pt11))) ; if line not assessed
                (setq LLine (LM:furthestapart (list (cadr LLine) (car LLine) Pt11 Pt10)))
              ) ; end progn
            ) ; end if Horizontal line
(princ LLine)
          ) ;end cond Line

        ) ; end conds
        (setq acount (+ acount 1))
      ) ; end while                                        ; End loop through selection set

      (if (= MLeaderPoint nil) ; if no arrow selected, use angled line. Have to lengthen to arrow length?
        (if (< (distance (car LLine) (car Knee) ) (distance (cadr LLine) (car Knee) ))
          (setq MLeaderPoint (cadr LLine))
          (setq MLeaderPoint (car LLine))
        ) ; end if
      ) ;end if

      (if (< (distance MLeaderPoint (nth 0 Knee)) (distance MLeaderPoint (nth 1 Knee)))
        (setq Knee (nth 0 Knee))
        (setq Knee (nth 1 Knee))
      )

      (command "_MLEADER" MLeaderPoint Knee MyText)      ; Draw Leader
      (command "erase" ss "" )                           ; Delete old objects
  )) ; end progn, end if ss


;;End Undo Mark
  (vla-endundomark thisdrawing) ; end undo mark
  (princ) ; end quietly
)

 

Posted

I selected the leader and the mtext and ran the lisp, this is what it came back with.

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

Things that may be of note:

The leaders have "arrow" set to none. 

The mtext and leaders were originally a surface elevation callout that was exploded twice, once to become a block reference, and the second time to make a leader and mtext.
If I just select the leader and execute the lips it says "0 found"
 

  • Like 1
  • 2 weeks later...
Posted

I don't think the person with the problem should get any credit.....

Big, Gigantic, Massive kudo's to Steven P here.....
(and also to Lee, ronjonp, BigAl, mhupp, Tharwat, hanhphuc, SLW210, rlx, and SO MANY MORE who have helped me in the past!!!!!!)

  • Like 2
Posted

If I remember correctly, a "surface elevation callout" may be a CIV3D label so you may be able to get at the properties ie Z so no need to explode.

 

This writes a Rl of a COGO point. Post a sample dwg show what the answer should look like. There is a convert  CIV3D objects to AutoCAD objects not sure if labels are in there.

 

CIV3D pt ht.lsp

Posted
On 10/16/2024 at 3:14 PM, BIGAL said:

If I remember correctly, a "surface elevation callout" may be a CIV3D label so you may be able to get at the properties ie Z so no need to explode.

 

This writes a Rl of a COGO point. Post a sample dwg show what the answer should look like. There is a convert  CIV3D objects to AutoCAD objects not sure if labels are in there.

 

CIV3D pt ht.lsp 898 B · 26 downloads

First thank you for this lisp and help. Unfortunately it does not work on the labels, and we don't use points, we just drop the label on the location we want. When I clicked on the label it said The lisp does not work for the elevation labels "Select object: ; error: ActiveX Server returned the error: unknown name: Location". I tested it on a cogo point (had to change text style to "standard" in the lisp routine) and it partially worked, but it didn't retain any text and created a text typing window that was blank.

I have attached screenshots of what the labels look like and the properties as well as when they are not dragged, and what they look like exploded twice (become a leader and mtext).

Something of note is some of the labels use information from 2 surfaces, or use a surface that compares the elevations between TC and gutter/street. Trying to get the labels as mleaders because the surface appears incorrect at places but the individual who created the surfaces did so with LandXMLs so we can't see into the definitions as we don't have that file.

Labels 2 surface.png

Label 1 surface.png

Exploaded label.png

lisp results.png

Posted (edited)

@Steven P
Hi Steven,
I wanted to follow up and see if you had a chance to look into it? My only idea right now is get the leader to Mleader add-in for autocad and either explode all of the labels at once, and do it twice then run the add-in individually but hopefully as a batch. 

From searching apparently anything to do with elevations has to be .NET (i have no idea what this means) but there is an example I found that converts a surface elevation label into a cogo point, I feel like half of the code would be beneficial for what I need but would have to figure out how to use the information pulled from the label to create an mleader. 
Full forum post:

 

(defun c:cc (/ ptss pt pt1 ss elev)
(vl-load-com)
(princ "\nPick your Surface label ... ")
(setq SS (ssget ":S:E" '((0 . "AECC_SURFACE_ELEVATION_LABEL"))))
(setq pt (osnap (cadar(cdddar (ssnamex ss 0))) "_ins"))
(setq lbl (vlax-ename->vla-object (ssname ss 0))
elev (vlax-invoke
(vlax-get lbl 'surface)
'findelevationatxy
(car pt)
(cadr pt)
)
)
(princ "\nSelect your target points")
(while
(setq ptSS (ssget '((0 . "AECC_COGO_POINT"))))
(setq i -1)
(while
(setq pt1 (vlax-ename->vla-object (ssname ptSS (setq i (1+ i)))))
(vlax-put pt1 'elevation elev)
)
)
(princ)
)

 

Edited by SLW210
Added Code Tags!
Posted (edited)

A couple of comments;

 

(princ "\nSelect your target points") remove code after this point and do your make mleader here. You are though missing information like the arrow length.

 

Run this code it should reveal all the properties for a AECC_SURFACE_ELEVATION_LABEL, then look at the RL code I provided. Please post result.

(vlax-Dump-Object (vlax-Ename->Vla-Object (car (entsel "\nPick a label ")) T))

 

It should return insertion point plus more info. 

 

The style of the label may need to be read separately this will provide details like arrow length and direction, often if you know how can get inside a CIV3D database using lisp rather than .NET. 

 

Post a dwg I use Bricscad more these days.

 

Edited by BIGAL
Posted

Hi DaveyR, I haven't had chance to look at this again yet - I'll see what time I have next week

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