Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: distance and offset along a polyline

  1. #11
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,197
    Login to Give a bone
    0

    Default Re: distance and offset along a polyline

    I am glad that some one else feels that is the important way to begin things, I am only going to post the part that is relative to this thread, you guys have already helped me out on other parts, and I already have parts that I knew how to write done.

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;select polyline
    (setq centerline (ssget ":S" '(( 0 . "*polyline"))))
     
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;select beginning
    (setq beginningpt (getpoint "nSelect Start Point"))
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;select start station
    (setq startsta (getint "nEnter Start Station"))
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;select points
     
    ;;select blocks on only particular layers with particular names (use insert point)
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;get station of point
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;get offset of point
     
    ;;;;;;;;;;;;;;;;;place text starting at 0+00 on both sides at 0,0 with proper scale distances;;;
    ;;(VbaAddText "text" (list x y z) 4 4)
    ;;By John W Anstaett 10/13/05
    ;;This function add a text object to modelspace
    ;; myText = the text to use
    ;; myPoint = list of the point
    ;; myHight = the text hight
    ;; myJustification = the Alignment
    ;;Alignment
    ;;acAlignment enum; read-write 
    ;;acAlignmentLeft = 0
    ;;acAlignmentCenter = 1
    ;;acAlignmentRight = 2
    ;;acAlignmentAligned = 3
    ;;acAlignmentMiddle = 4
    ;;acAlignmentFit = 5
    ;;acAlignmentTopLeft = 6 
    ;;acAlignmentTopCenter = 7
    ;;acAlignmentTopRight = 8
    ;;acAlignmentMiddleLeft = 9
    ;;acAlignmentMiddleCenter = 10
    ;;acAlignmentMiddleRight = 11
    ;;acAlignmentBottomLeft = 12
    ;;acAlignmentBottomCenter = 13
    ;;acAlignmentBottomRight = 14
    ;; the function return the textobj as a vbaobject
    ;; so you can use make other change to the object
    ;;Exp:
    ;;(vla-put-layer myreturn "layername")
    ;;(vla-put-width myreturn 0.5)
    ;;(vla-put-textstyle myreturn "newstyle")
    (vl-load-com) 
    ;;This function loads the extended AutoLISP functions provided
    ;;with Visual LISP. The Visual LISP extensions implement ActiveX
    ;;and AutoCAD reactor support through AutoLISP, and also provide
    ;;ActiveX utility and data conversion functions, dictionary handling
    ;;functions, and curve measurement functions. 
    ;;If the extensions are already loaded, vl-load-com does nothing
    (defun VbaAddText (myText myPoint myHight MyJustification / acadObject acadDocument myss myas myc vlss)
      (setq acadObject (vlax-get-acad-object));get Autocad object
      (setq acadDocument (vla-get-ActiveDocument acadObject));get the Activedocument object
      (setq acadModelSpace (VLA-GET-MODELSPACE acadDocument));get the modelspace block
      (setq mytextObj (vla-addtext acadModelSpace mytext (vlax-3d-point myPoint) myhight));add text
      (vla-put-Alignment mytextObj myJustification);set text Justification
      (setq mytextObj myTextobj);retrun the text object
    )
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  2. #12
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: distance and offset along a polyline

    Oh, good, you have a start on the project.
    I'll help you with the distance part and perhaps someone else will fill in.
    I have to get some work done today too.


    Code:
    ;;  no error checking at this time
    (defun c:myroutine ()
      ;; Select ONLY polyline
      ;;   Note, need to trap ENTER
      (prompt "\nSelect a polyline.")
      (setq ss (ssget "+.:E:S" '((0 . "LWPOLYLINE,POLYLINE"))))
      (setq ename (ssnamex ss 0) ; look this function up in the help
            selpt (last (last (car ename))) ; the pick point
            ename (cadar ename) ; the entity name
      )
      ;; Pick end point of THE SELECTED ployline
      ;;   Note, need to trap ENTER and missed endpoint of matching pline
      (setq pt (getpoint "\nPick the endpoint of the polyline."))
      ;; Get distance ALONG THE POLYLINE from select point to pick point
      ;;  Note, use vlax-curve-getDistAtPoint but to use it we need to determine
      ;;  if the picked point is the END or START of the pline
    
      ;; get the actual point on the pline for the select point
      ;; this assures that the point is ON the pline not next to it
      (setq selpt (vlax-curve-getclosestpointto ename selpt))
    
      ;;  get the actual point on the pline fot the picked point
      ;; and get the distance
      (if (< (distance pt (vlax-curve-getstartpoint ename))
             (distance pt (vlax-curve-getendpoint ename))
          )
        ;;  pt is START of pline
        (setq pkpt (vlax-curve-getendpoint ename)
              dist (vlax-curve-getdistatpoint ename selpt)
        )
        ;; pt is END of pline
        (setq pkpt (vlax-curve-getstartpoint ename)
              ;;  (- <total length> <dist to selpt>) 
              dist (- (vlax-curve-getdistatpoint ename (vlax-curve-getEndPoint ename))
                      (vlax-curve-getdistatpoint ename selpt))
        )
      )
    
    
    
    
    
      (princ)
    )

  3. #13
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,197
    Login to Give a bone
    0

    Default Re: distance and offset along a polyline

    CAB, I'm sorry, I must not be understanding what your code actually does. it is probably simple, but I am not that familiar with vlax commands. I have posted the whole code that has to do with this part of my program, including all the modifications I made this weekend. Your code might be out of place as to how you intended it. on my parts of the program, I only have parts that I knew how to write, the station and offset areas still need the basic functions to determine the station and offset, I just coded how to convert the station to the text that I need displayed.

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;select polyline AND BEGINNING
    ;;  no error checking at this time
    (defun c:PLINESELECT ()
      ;; Select ONLY polyline
      ;;   Note, need to trap ENTER
      (prompt "nSelect a polyline.")
      (setq ss (ssget "+.:E:S" '((0 . "*POLYLINE"))))
      (setq ename (ssnamex ss 0)  ; look this function up in the help
     selpt (last (last (car ename))) ; the pick point
     ename (cadar ename)  ; the entity name
      )
      ;; Pick end point of THE SELECTED ployline
      ;;   Note, need to trap ENTER and missed endpoint of matching pline
      (setq pt (getpoint "nPick the endpoint of the polyline."))
      ;; Get distance ALONG THE POLYLINE from select point to pick point
      ;;  Note, use vlax-curve-getDistAtPoint but to use it we need to determine
      ;;  if the picked point is the END or START of the pline
      ;; get the actual point on the pline for the select point
      ;; this assures that the point is ON the pline not next to it
      (setq selpt (vlax-curve-getclosestpointto ename selpt))
      ;;  get the actual point on the pline fot the picked point
      ;; and get the distance
      (if (< (distance pt (vlax-curve-getstartpoint ename))
      (distance pt (vlax-curve-getendpoint ename))
    	  )
    	;;  pt is START of pline
    	(setq pkpt (vlax-curve-getendpoint ename)
       dist (vlax-curve-getdistatpoint ename selpt)
    	)
    	;; pt is END of pline
    	(setq pkpt (vlax-curve-getstartpoint ename)
       ;;  (- <total length> <dist to selpt>) 
       dist (- (vlax-curve-getdistatpoint
    	  ename
    	  (vlax-curve-getEndPoint ename)
    	)
    	(vlax-curve-getdistatpoint ename selpt)
    		)
    	)
      )
      (princ)
    )
    (C:PLINESELECT)
    ;;;;;;;;;;;;;;;;;;;;;;;;;select start station
    (setq startsta (getint "nEnter Start Stationn"))
    ;;;;;;;;;;;;;;;;;;;;;;;;;select points
    ;;select blocks on only particular layers with particular names (use insert point)
    (setq pointlist
    	   (ssget
      "_X"
      (LIST
    	'(-4 . "<AND")
    	(CONS 410 (GETVAR "ctab"))
    	'(-4 . "<OR")
    	'(0 . "insert")
    	'(8
    	  .
    	  "BNDPT,BNDPTS,FEATURE,FEATIURE,GDRL,EXIST TELE,TREELINE,UTILELEC,UTILSTORM,UTILCOMM,UTILSAN,UTILGAS,TREELINE,BLDGPT"
    	 )
    	'(-4 . "OR>")
    	'(-4 . "AND>")
      );END LIST
    	   );END SSGET
    );END SETQ
    ;;;;;;;;;;;;;;;;;;;;;;;;;get station of point
    (while (setq staoff (ssname ss 0))
    	  (setq whole (/ sta 100)
    	  remainder (* (rem sta 100) 100)
    	   station (strcat whole "+" remainder))
    ;;;;;;;;;;;;;;;;;;;;;;;;;get offset of point
     
    ;;;;;;;;;;;;;;;;;place text starting at 0+00 on both sides at 0,0 with proper scale distances;;;
    (vl-load-com) 
    ;(defun C:OffsetText ()
      (setq acadObject (vlax-get-acad-object)) ;get Autocad object
      (setq acadDocument (vla-get-ActiveDocument acadObject))
    	 ;get the Activedocument object
      (setq acadModelSpace (VLA-GET-MODELSPACE acadDocument))
    	 ;get the modelspace block
      (if (< (- sta sta1) (* 1.5 text_height))
    	(setq sta (+ sta1 (* 1.5 text_height)))
    	(setq sta1 sta)
      );end if
      (setq ofsl (* 22.5235 aoscale)
     ofsr (* 7.35 aoscale)
      );end setq
      (if (< (atoi offset) 0)
    	(setq Insertpoint (list (sta,ofsl, "0")))
    	(setq Insertpoint (list (sta,ofsr, "0")))
      );end if
      (setq textObj (vla-addtext
    	acadModelSpace
    	(strcat station description offset)
    	(vlax-3d-point Insertpoint)
    	text_height
      );end vla-addtext
      );end setq
      (if (< (atoi offset) 0)
    	(vla-put-Alignment textObj 11) ;set text Justification
    	(vla-put-Alignment textObj 9) ;set text Justification
      )	 ;end if
    	 ;(setq mytextObj myTextobj);retrun the text object
    )	 ;end while
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  4. #14
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: distance and offset along a polyline

    Do you mind if we go back to the beginning?
    Start with pseudo code.
    This I extracted from you previous post. Can you expand on each line item with more detail as to what
    you want to accomplish. I know it's a lot of writing but it will put me on the same page with you
    in terms of your goal & will help calcify your intended action at each point.

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;select polyline
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;select beginning
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;select start station
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;select points
     
    ;;select blocks on only particular layers with particular names (use insert point)
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;get station of point
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;get offset of point
     
    ;;;;;;;;;;;;;;;;;place text starting at 0+00 on both sides at 0,0 with proper scale distances

  5. #15
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,197
    Login to Give a bone
    0

    Default Re: distance and offset along a polyline

    Code:
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;select polyline
    ;;select the centerline of the project (it will probablly be a 2d polyline, *polyline will work)
    ;;;;;;;;;;;;;;;;;;;;;;;;;select beginning
    ;;select the beginning point of the polyline (start point may not be necassary)
    ;;;;;;;;;;;;;;;;;;;;;;;;;select start station
    ;;some projects dont nessasarily start at 0+00, some might start at 100+00, this part should account for that)
    (setq startsta (getint "\nEnter Start Station\n"))
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;select points
     
    ;;select blocks on only particular layers with particular names (use insert point)
    (setq pointlist
    	 (ssget
    "_X"
    (LIST
    	'(-4 . "<AND")
    	(CONS 410 (GETVAR "ctab"))
    	'(-4 . "<OR")
    	'(0 . "insert")
    	'(8
    	 .
    	 "BNDPT,BNDPTS,FEATURE,FEATIURE,GDRL,EXIST TELE,TREELINE,UTILELEC,UTILSTORM,UTILCOMM,UTILSAN,UTILGAS,TREELINE,BLDGPT"
    	 )
    	'(-4 . "OR>")
    	'(-4 . "AND>")
    );END LIST
    	 );END SSGET
    );END SETQ
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;get offset of point
    ;;find the perpindicular distance from the selected point to the centerline
     
    ;;;;;;;;;;;;;;;;;;;;;;;;;get station of point
    ;;find the distance along the centerline to the perpindicular point in the last step
    (while (setq staoff (ssname ss 0))
    	 (setq whole (/ sta 100)
    	 remainder (* (rem sta 100) 100)
    	 station (strcat whole "+" remainder));this part of the code converts the distance to the text that will be used below
     
    ;;;;;;;;;;;;;;;;;place text starting at 0+00 on both sides at 0,0 with proper scale distances
    ;;using the station value, place text beginning as though 0 is 0+00
    (vl-load-com) 
    ;(defun C:OffsetText ()
    (setq acadObject (vlax-get-acad-object)) ;get Autocad object
    (setq acadDocument (vla-get-ActiveDocument acadObject))
    	 ;get the Activedocument object
    (setq acadModelSpace (VLA-GET-MODELSPACE acadDocument))
    	 ;get the modelspace block
    (if (< (- sta sta1) (* 1.5 text_height))
    	(setq sta (+ sta1 (* 1.5 text_height)))
    	(setq sta1 sta)
    );end if
    (setq ofsl (* 22.5235 aoscale)
    ofsr (* 7.35 aoscale)
    );end setq
    (if (< (atoi offset) 0)
    	(setq Insertpoint (list (sta,ofsl, "0")))
    	(setq Insertpoint (list (sta,ofsr, "0")))
    );end if
    (setq textObj (vla-addtext
    	acadModelSpace
    	(strcat station description offset);offset will be calculated above in the offset portion, description needs to be extracted from the appropriate attribute of the selected block
    	(vlax-3d-point Insertpoint)
    	text_height
    );end vla-addtext
    );end setq
    (if (< (atoi offset) 0)
    	(vla-put-Alignment textObj 11) ;set text Justification
    	(vla-put-Alignment textObj 9) ;set text Justification
    )	 ;end if
    	 ;(setq mytextObj myTextobj);retrun the text object
    )	 ;end while
    the while loop is to get this thing to loop until all points in the selection set have been annotated originally I had station first, but it might be easier to calc the offset first, then use that information to get the station, it might not be the proper way to loop the program, any better ideas are definitely welcome.
    Last edited by ccowgill; 2006-05-30 at 12:26 PM. Reason: \ did not show up
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  6. #16
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: distance and offset along a polyline

    Off on an errand, will look when I get back.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Reset Offset Distance
    By Wish List System in forum AutoCAD Wish List
    Replies: 5
    Last Post: 2020-01-17, 04:50 PM
  2. LISP to offset polyline an increasing distance
    By dooley1971392018 in forum AutoLISP
    Replies: 0
    Last Post: 2015-03-25, 12:05 AM
  3. OFFSET WITH 20% OF MEASURED DISTANCE.
    By aijazahmed in forum AutoLISP
    Replies: 3
    Last Post: 2014-06-05, 04:12 PM
  4. 2010: Offset Distance
    By lswinea in forum AutoCAD General
    Replies: 2
    Last Post: 2011-10-18, 01:35 AM
  5. Replies: 0
    Last Post: 2011-10-11, 08:38 AM

Posting Permissions

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