Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp for Intersections

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
williamcastojr
1232 Views, 11 Replies

Lisp for Intersections

I'm trying to find a lisp that will find  Intersecting lines and put a point on it. With a tag to pick up the closet text Z value. These are Blocks that was Flatten. With no attributes. I looked but all is cad points. Thanks  

11 REPLIES 11
Message 2 of 12
hosneyalaa
in reply to: williamcastojr

Hi

Attached drawing for example 

Message 3 of 12

Here you go 

Message 4 of 12

Trying to learn this-

  • Build a list of positions.  Loop through (in this case) all the lines that are within the specified size, and check to see which ones intersect.  If two lines are short enough, then intersect them and save the intersection point (X/Y) to a list of the NODES.
  • Build a selection set of text / mtext objects then calculate the coordinates at ALL FOUR corners. You can't count on the insertion point being closest.  Save the list of four points to a RECTANGLE list (with the text string).
  • Begin looping through the NODES, for each node look through the rectangles, find the rectangle point (corner) that's closest to the node, use the text value as the elevation (you already had the X/Y) and you've got the point.

 

Message 5 of 12
hosneyalaa
in reply to: williamcastojr

please
Attach the drawing  civil 3d  2016 

Message 6 of 12

her you go

Message 7 of 12
hosneyalaa
in reply to: williamcastojr

try

 

 

 ;; ;   ; Jeff mishler
  ;;borrowed FindNumbers function as posted by MP to the Swamp
(defun FindNumbers (String / Distil NumList Result)
    (defun Distil (lst)
      (while (eq 46 (car lst)) (setq lst (cdr lst)))
      (setq lst (reverse lst))
      (while (eq 46 (car lst)) (setq lst (cdr lst)))
      (reverse lst)
    )
    (foreach Code
                  (reverse
                    (mapcar
                      '(lambda (Code)
                         (if (or (< 47 Code 58) (eq 46 Code))
                           Code
                           32
                         )
                       )
                      (vl-string->list String)
                    )
                  )
      (if (eq 32 Code)
        (if NumList
          (setq
            Result  (cons NumList Result)
            NumList nil
          )
        )
        (setq NumList (cons Code NumList))
      )
    )
    (mapcar 'vl-list->string
            (vl-remove-if
              'null
              (mapcar 'Distil
                      (if NumList
                        (cons NumList Result)
                        Result
                      )
              )
            )
    )
  )


  ;; ;   ; Jeff mishler
 
(defun c:TESTATT (/ *ACAD* ATTS BLK BLKSOBJ C3D C3DDOC CODE DOC ELEV ENAME ENT IDX OBJ OCOGO OLDSTR PNTNUMS PNTS PT SPC SS)

  
  
(setvar "CMDECHO" 0)
(command "-osnap" "off")



   ;; ;   ; Jeff mishler
  (setq *acad* (vlax-get-acad-object))
  (setq C3D (strcat "HKEY_LOCAL_MACHINE\\"
                    (if vlax-user-product-key
                      (vlax-user-product-key)
                      (vlax-product-key)
                    )
            )
        C3D (vl-registry-read C3D "Release")
        C3D (substr
              C3D
              1
              (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1))
            )
        C3D (vla-getinterfaceobject
              *acad*
              (strcat "AeccXUiLand.AeccApplication." C3D)
            )
  )

  
  (setq C3Ddoc (vla-get-activedocument C3D))
  (setq pnts (vlax-get C3Ddoc 'points))
  

   
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq blksObj (vla-get-blocks doc))
  (vla-endundomark doc)
  (vla-startundomark doc)
  (setq spc (vla-get-modelspace doc))
;;;  (setq ss (ssget  '((0 . "INSERT") )))
;;;  (setq ss (ssget  "x" '((0 . "INSERT") (66 . 1))))
  (if (setq ss (ssget  '((0 . "INSERT") )))
    (progn
      (setq idx -1)
      (while (setq ent (ssname ss (setq idx (1+ idx))))
        (setq atts (vlax-invoke
                     (setq blk (vlax-ename->vla-object ent))
                     'getattributes
                   )
        )
        (if atts
          (progn
	    
	    (if (= oldstr nil)
	      (SETQ oldstr (CAR(LM:listbox "Select an Item" (MAPCAR '(lambda (x)(vlax-get x 'tagstring)) atts) 1)))
	      )
	    
	    (setq pt (vlax-get blk 'insertionpoint))
	    
            
            
;;;            (vla-put-layer c3dPt (vla-get-layer blk))
	    
            (foreach att atts
;;;	      (setq att (CADDR atts))
              (cond 
                    (
		     (eq (vla-get-tagstring att) oldstr)
                     (setq elev (findnumbers (vla-get-textstring att)))
                     (if elev
		       (progn
		       (setq ename (list (car pt) (cadr pt) (atof (car elev))))
		       (setq oCogo(vlax-invoke pnts 'add ename))
		       (vlax-put oCogo 'rotation (vla-get-rotation blk))
	               (setq pntnums (vlax-get oCogo 'number))
	                (vla-put-NAME oCogo (strcat "EXPLODE CIVIL POINT & " (itoa pntnums)));NAME   NETWORK;NAME   NETWORK
	              (vla-put-description oCogo "CONVERT");  NAME MANHOLE
	              (vlax-put-property oCogo 'Style (strcat "Benchmark"))
	              (vlax-put-property oCogo 'LabelStyle "Elevation Only")
		       )

                       
                     )
                    )
                    
              )
            )
 

          );(progn
	  (progn
	    (setq obj (vlax-ename->vla-object ent))
	  
	  (setq pt (vlax-get obj 'insertionpoint))
	  (setq ename (list (car pt) (cadr pt) (GetLevel (vla-get-name obj) blksObj)))
	    (setq oCogo(vlax-invoke pnts 'add ename)) 
	               (setq pntnums (vlax-get oCogo 'number))
	                (vla-put-NAME oCogo (strcat "EXPLODE CIVIL POINT & " (itoa pntnums)));NAME   NETWORK;NAME   NETWORK
	              (vla-put-description oCogo "CONVERT");  NAME MANHOLE
	              (vlax-put-property oCogo 'Style (strcat "Benchmark"))
	              (vlax-put-property oCogo 'LabelStyle "Elevation Only")


	
	
	    
	   )
        );IF
      );(progn
      (princ
        "\nEagle Point points have been converted to Civil 3D points."
      )
    );(progn
  );IF
  (vlax-release-object c3d)



 (command "_undo" "_end")
(setvar "CMDECHO" 1)
    (princ)

  (princ)
);;END



;; Roy_043 
 (defun GetLevel (nme blksObj / out)
  (vlax-for obj (vla-item blksObj nme)
    (cond
      (out)
;;;      ((/= "V-NODE-TEXT" (strcase (vla-get-layer obj)))
;;;        nil
;;;      )
      ((= "AcDbBlockReference" (vla-get-objectname obj))
        (setq out (GetLevel (vla-get-name obj) blksObj))
      )
      ((not (vlax-property-available-p obj 'textstring))
        nil
      )
      ((wcmatch (vla-get-textstring obj) "*#.#*")
        (setq out (last (LM:parsenumbers (vla-get-textstring obj))))
      )
    )
  )
)



  ;; Parse Numbers  -  Lee Mac
;; Parses a list of numerical values from a supplied string.

        (defun LM:parsenumbers ( str )
    (   (lambda ( l )
            (read
                (strcat "("
                    (vl-list->string
                        (mapcar
                           '(lambda ( a b c )
                                (if (or (< 47 b 58)
                                        (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                                        (and (= 46 b) (< 47 a 58) (< 47 c 58))
                                    )
                                    b 32
                                )
                            )
                            (cons nil l) l (append (cdr l) '(()))
                        )
                    )
                    ")"
                )
            )
        )
        (vl-string->list str)
    )
)





;;-----------------------=={ List Box }==---------------------;;
;;                                                            ;;
;;  Displays a List Box allowing the user to make a selection ;;
;;  from the supplied data.                                   ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  title    - List Box Dialog title                          ;;
;;  data     - List of Strings to display in the List Box     ;;
;;  multiple - Boolean flag to determine whether the user     ;;
;;             may select multiple items (T=Allow Multiple)   ;;
;;------------------------------------------------------------;;
;;  Returns:  List of selected items, else nil.               ;;
;;------------------------------------------------------------;;

(defun LM:ListBox ( title data multiple / file tmp dch return )
  ;; © Lee Mac 2011
  
  (cond
    (
      (not
        (and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
          (write-line
            (strcat "listbox : dialog { label = \"" title
              "\"; spacer; : list_box { key = \"list\"; multiple_select = "
              (if multiple "true" "false") "; } spacer; ok_cancel;}"
            )
            file
          )
          (not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch)
        )
      )
    )
    (
      t     
      (start_list "list")
      (mapcar 'add_list data) (end_list)

      (setq return (set_tile "list" "0"))
      (action_tile "list" "(setq return $value)")

      (setq return
        (if (= 1 (start_dialog))
          (mapcar '(lambda ( x ) (nth x data)) (read (strcat "(" return ")")))
        )
      )          
    )
  )
  
  (if (< 0 dch) (unload_dialog dch))
  (if (setq tmp (findfile tmp)) (vl-file-delete tmp))

  return
)

 

 

111.gif

Message 8 of 12

Works on one at a time like a champ!!! I'm getting this  error: Automation Error. The parameter is incorrect.

Message 9 of 12
hosneyalaa
in reply to: williamcastojr

Select only points blocks 

If you're selected anther blocks 

Giving this error s 

 

Message 10 of 12

I must have a setting wrong some where. I grabbed the exact points you did same thing one at a time.

 

Message 11 of 12

I new to this maybe I copied it wrong?

Message 12 of 12

Got it Did not have a template!! Thank you for your Time works like a champ

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report