+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Newbie
    Discipline
    Construction
    Using
    AutoCAD 2009
    Join Date
    Dec 2016
    Posts
    8

    Question offset table (intersection points)

    Registered forum members do not see this ad.

    hi all,

    i have drawings that contains stations and waterlines as polyline or spline.
    (in att. dwg named as ST0, ST1...ST20, and WL0 to WL
    there may be other stations or waterlines such as ST0.5, ST1.5, WL9, WL10...
    i need a table that shows distance of intersection points from CL. (see att. dwg)
    is it possible to make this table by lisp?
    Attached Files

  2. #2
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    655

    Default

    Suggestion: make all layers unique for each (section) lwpolyline, i.e: "ST0" "ST1" "ST10" etc..
    otherwise we can't populate the intersection points if all sections are in same layer "ST17" ?!

    Code:
    (vl-load-come)
    
    ;Rev 1
    (defun c:test1 (/ *error* p ss lst fn f  hp:table ) ;<-- localize=output csv, global=output table, i.e: To remove hp:table from variable list
      ;hanhphuc 15.05.2018
      (defun *error* (msg)
        (if	f
          (close f)
          ) 
        )
    
      (if (and
    	(setq p (getpoint "\nSpecify base point.. "))
    	(setq ss (ssget '((0 . "LWPOLYLINE") (8 . "GRID,*ST*"))))
    		(setq lst (mapcar ''((x)
    				(setq obj (vlax-ename->vla-object x))
    				(cons (vla-get-Layer obj)
    				 (reverse (mapcar ''((a / ip)
    				      (if
    				       (setq ip (vlax-invoke obj 'intersectwith (vlax-ename->vla-object a) AcExtendNone))
    				       (rtos (* (-(car (trans ip 0 1))(car p)) 1e-3) 2 3)
    				       "-"
    				       )
    				      )
    				    (vl-remove-if ''((x)(or (apply 'equal (append (mapcar ''((f) (car (trans ( f x ) 0 1 )))
    									   (list vlax-curve-getstartpoint vlax-curve-getEndpoint)) '(1e-3))
    							     )
    							 (not (wcmatch (cdr(assoc 8 (entget x))) "GRID") )
    							 )
    						     ) (acet-ss-to-list ss))
    				   )
    				  )
    				 )
    				)
    			    (vl-remove-if-not ''((x)(wcmatch (cdr(assoc 8 (entget x))) "*ST*" )) (acet-ss-to-list ss))
    			     )
    		 )
    	   (setq lst (cons '("SECTIONS" "WL0.0" "WL0.5" "WL1.0" "WL2.0" "WL3.0" "WL4.0" "WL5.0" "WL6.0" "WL7.0" "WL8.0")
    			   (vl-sort lst
    			      ''((a b) (apply '< (mapcar ''((x) (car (LM:parsenumbers x))) (list (car a) (car b)))))) )
    		 )
    	
    	   ); and
      	   (if (and hp:table (setq p (getpoint "\nSpecify insertion point.. ")))
    	       (hp:table lst (trans p 1 0) "OFFSET TABLE" (getvar 'textsize))
    	       (progn
       		(and (setq fn (vl-filename-mktemp "tmp" (getvar 'dwgprefix) ".csv"))
    	   		(setq f (open fn "w"))
    		 (foreach x lst (write-line (apply 'strcat (mapcar ''((a) (strcat a ",")) x)) f))
    		    (progn (if	f (close f) ) 
    		    (vl-cmdf "start" fn)
    		      )
    		     )
    		    ) 
    	     ); if 
    
        (princ "\nNothing!")
        
        ) 
      (princ)
      ) ;_ end of defun
    
    
    ;; 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)
        )
    )
    This routine is only a test on drawing you provided,
    i.e. you need to modify the TEXTSIZE to suit your drawing


    Command: TEXTSIZE
    then edit new value 200.0

    or add (setvar 'textsize 200.) as default in the code
    Last edited by hanhphuc; 18th May 2018 at 03:24 pm. Reason: rev1, allow pick base point
    _$ ( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" )
    ; error: too many arguments

  3. #3
    Forum Newbie
    Discipline
    Construction
    Using
    AutoCAD 2009
    Join Date
    Dec 2016
    Posts
    8

    Default

    hi hanhphuc,

    thnx for great code and suggestion. really fast job.
    but i think something missing about "hp:table" that i dont have.
    so the code gives me only temp001.csv file.
    can u fix this?

  4. #4
    Forum Newbie
    Discipline
    Construction
    Using
    AutoCAD 2009
    Join Date
    Dec 2016
    Posts
    8

    Default

    is there another way to make autocad table from the csv file?

  5. #5
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    655

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by bkartal16 View Post
    hi hanhphuc,

    thnx for great code and suggestion. really fast job.
    but i think something missing about "hp:table" that i dont have.
    so the code gives me only temp001.csv file.
    can u fix this?
    hi, actually you can direct copy from .csv then paste as OLE object in ACAD.

    This forum as we are volunteers , we prefer OP attempt to code & solve it, sometimes busy may overlook.

    it was external global function omitted, so should be unique name
    Code:
    (defun hp:TABLE ( lst pt str sz / obj r i )
      ;hanhphuc 
    
    ;RetVal = object.AddTable(InsertionPoint, NumRows, NumColumns, RowHeight, ColWidth)  
    
      (setq	
    	obj
    	 (vlax-invoke
    	   ((lambda (doc)
    	      (foreach x '(ActiveDocument ActiveLayout Block) (setq doc (vlax-get doc x)))
    	      ) 
    	     (vlax-get-acad-object)
    	     )
    	   'AddTable
    	   pt 			; InsertionPoint
    	   (if str
    	     (+ 1 (length lst)) ; NumRows
    	     (length lst)
    	     ) 
    	   (length (car lst)) 	; NumColumns
    	   (* sz 3.0) 		; RowHeight
    	   (* sz 10.)		; ColWidth
    	   ) 
    	) 
      
      (foreach x (list acTitleRow acHeaderRow acDataRow)
            (vla-settextheight obj x sz)
            (vla-settextStyle obj x (getvar 'textStyle))
        )
    
    (setq r	(if str
    	  (progn (vla-settext obj 0 0 str) 1 ) 0
    	   ) 
          ) 
      (foreach x lst
        (setq i 0) 
        (foreach $ x
          (vla-setcellalignment obj r i acMiddleCenter)
          (vla-settext obj r i $)
          (setq i (1+ i))
          ) ;_ end of foreach
        (setq r (1+ r))
        ) ;_ end of foreach
      (vla-put-regeneratetablesuppressed obj :vlax-false)
      obj
      ) ;_ end of defun
    Here's another workaround
    1.pick base point at zero axis
    2.select crossing or window
    3.Insert table


    _$ ( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" )
    ; error: too many arguments

Similar Threads

  1. Replies: 2
    Last Post: 21st Dec 2012, 02:11 am
  2. Intersection points
    By SELFCAD in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 9th May 2012, 01:09 pm
  3. retrieving the points of an intersection...
    By Lt Dan's legs in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 3rd Nov 2010, 07:02 pm
  4. Intersection points
    By Small Fish in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 23rd Oct 2009, 02:08 am
  5. Points Of Intersection
    By robertbulmer in forum Catch All
    Replies: 1
    Last Post: 2nd Mar 2009, 09:45 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts