Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Convert Survey Figure and Feature Line to 2D Polyline

  1. #1
    Wish List Administration
    Join Date
    2007-08
    Posts
    434

    Default Convert Survey Figure and Feature Line to 2D Polyline

    Summary: New commands that convert survey figures and feature lines to 2D polylines in one step.

    Description: Convert "survey figure and feature line to 2D polyline".
    Now we can explode a survey figure to a 3D polyline in Civil2009 but lost the curves and arcs.

    How Used: Een menu:
    Grading -> Polyline utilities -> Convert survey figure to 2D polyline.
    Grading -> Polyline utilities -> Convert feature line to 2D polyline.

    Feature Affinity: Import/Export

    Submitted By: Wim De Winter on September 2, 2008

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    I've recently needed this feature, so I came up with this. It seems to work for most things I have tested it on.

    Code:
    (defun _ConvertFigureToPolyline	(oFigure      /		   
    				 arr2DPoints  arrSpace	   fr
    				 i	      lst2dPoints  lstBulge
    				 lstVariables objPolyline  ss
    				 x	 y	      z
    				)
    
    
      ;;====================
      ;; Begin Main Routine 
      ;;====================
    
      (setq	i  -1
    	x  0
    	fr (_safelist (vlax-invoke-method oFigure 'GetPoints 1))
      )
      (repeat (/ (length fr) 3)
        (setq y (1+ x)
    	  z (1+ y)
    	  lst2DPoints
    	   (append lst2DPoints (list (nth x fr) (nth y fr)))
    	  lstBulge
    	   (append lstBulge
    		   (list
    		     (vlax-invoke-method
    		       oFigure
    		       'GetBulgeAtPoint
    		       (vlax-3d-point
    			 (list (nth x fr) (nth y fr) (nth z fr))
    		       )
    		     )
    		   )
    	   )
    	  x (+ x 3)
        )
      )
      (setq	arrSpace
    	 (vlax-make-safearray
    	   vlax-vbdouble
    	   (cons 0 (- (length lst2DPoints) 1))
    	 )
      )
      (setq arr2DPoints (vlax-safearray-fill arrSpace lst2DPoints))
      (vlax-make-variant arr2DPoints)
      (_SetSysVar "clayer" (vla-get-layer oFigure))
      (if (not (tblsearch "LAYER" strBreaklineLayer))
        (_AddLayer strBreaklineLayer)
      )
      (vla-put-layer oFigure strBreaklineLayer)
      (setq	objPolyline
    	 (vlax-invoke-method
    	   (_Space)
    	   'AddLightWeightPolyline
    	   arr2DPoints
    	 )
      )
      (foreach n lstBulge
        (vla-setbulge objPolyline (setq i (1+ i)) n)
      )
    )
    
    (defun c:figure2poly (/		   _AddLayer	_Space
    		      _SetSysVar   *Error*	strBreakline
    		      _safelist	   _variantvalue
    		      ss	   oFigure
    		     )
      (vla-startundomark
        (vla-get-activedocument (vlax-get-acad-object))
      )
      ;;===================================
      ;; Initiliaze user defined variables 
      ;;===================================
      (setq strBreaklineLayer "breakline")
      ;;===================
      ;; Defun subroutines 
      ;;===================
    
      ;;_ Returns the active space object
      (defun _Space	(/ *DOC* space)
        (setq *DOC* (vla-get-activedocument (vlax-get-acad-object)))
        (setq space	(if (= 1 (vla-get-activespace *DOC*))
    		  (vla-get-modelspace *DOC*) ;_ Model Space
    		  (if (= (vla-get-mspace *DOC*) :vlax-true)
    		    (vla-get-modelspace *DOC*) ;_ Model Space through Viewport
    		    (vla-get-paperspace *DOC*) ;_ Paper Space
    		  )
    		)
        )
      )
    
      (defun *error* (strMessage /)
        (if	(or
    	  (= strMessage "Function cancelled") ; If user cancelled
    	  (= strMessage "quit / exit abort") ; If user aborted
    	  (null strMessage)		; End quietly
    	)				; End or sequence
          (princ)				; Exit quietly
          (princ (strcat "\nError: " strMessage)) ; Report Error
        )
        (if	lstVariables
          (mapcar '(lambda (x) (setvar (car x) (cdr x))) lstVariables)
        )
        (vla-endundomark
          (vla-get-activedocument (vlax-get-acad-object))
        )
        (princ)
      )
    
      ;;_ Adjust system variable and save original to list
      (defun _SetSysVar (name value /)
        (if	lstVariables
          (if (null (assoc name lstVariables))
    	(setq lstVariables
    	       (append lstVariables
    		       (list (cons name (getvar name)))
    	       )
    	)
          )
          (setq lstVariables (list (cons name (getvar name))))
        )
        (setvar name value)
      )
    
     ;_ Add a new layer to the layers collection
     ;_ Syntax (AddLayer "layername")
     ;_ Function returns T if successful nil if not
      (defun _AddLayer (strLayerName / objLayer)
        (if	(and (= (type strLayerName) 'STR)
    	     (not (tblsearch "LAYER" strLayerName))
    	)
          (progn
    	(setq
    	  objLayer (vla-add
    		     (vla-get-layers
    		       (vla-get-activedocument (vlax-get-acad-object))
    		     )
    		     strLayerName
    		   )
    	)
    	(vlax-release-object objLayer)
    	t
          )
        )
      )
    
     ;_ Convert Safearray to list
      (defun _safelist (value)
        (if	(= (type value) 'VARIANT)
          (setq value (_variantvalue value))
        )
        (setq value (vl-catch-all-apply 'vlax-safearray->list (list value)))
        (if	(vl-catch-all-error-p value)
          nil
          value
        )
      )
     ;_ Get value of variant
      (defun _variantvalue (value)
        (setq value (vl-catch-all-apply 'vlax-variant-value (list value)))
        (if	(vl-catch-all-error-p value)
          nil
          value
        )
      )
    
      (princ
        "\rConvert a feature line or survey figure to polyline... "
      )
      (if (setq ss (ssget ":S:E" '((0 . "AECC_SVFIGURE,AECC_FEATURE_LINE"))))
        (progn
          (setq oFigure
    	     (vlax-ename->vla-object (ssname ss 0))
          )
          (_ConvertFigureToPolyline oFigure)
        )
      )
      (*error* nil)
    )
    To use it, of course, you will need to copy and paste it to a file with a .lsp file extension and then load that file into the drawing. There are numerous ways to load autolisp files with many posted throughout these forums.

    Once it is loaded, you would execute the command with figure2poly. Then select the feature line or survey figure you wish to convert. The routine will generate a new 2d polyline on the layer which the selected object resides. It will then change the layer of the selected object to a "breakline" layer. This portion of the routine could be changed, but I'll leave it to others to work out.

    I believe I have all necessary sub-routines included in the code above. If it is telling you a routine is not available, please let me know so I can provide it.

    HTH,
    Opie
    Last edited by Opie; 2015-04-08 at 05:46 PM. Reason: fixed reported error
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Member
    Join Date
    2015-04
    Posts
    6

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    Opie,

    I have been desperately looking for a routine like this to convert survey figures to 2D polylines! However, when I run this routine, I get an error message (Error: bad argument type: numberp: nil) after selecting the figure line. I'm using Civil 3D 2015. Any thoughts? Any help would be greatly appreciated!!

    Steve

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    Do you have a sample drawing you can upload which exhibits this behavior?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Member
    Join Date
    2015-04
    Posts
    6

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    Here's a sample file...
    Attached Files Attached Files

  6. #6
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    I've edited the code above, which appears to not throw the reported error. In trying to clean code out for public use, which does not have access to my other routines, I missed something. Let me know if it is working (or not).
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  7. #7
    Member
    Join Date
    2015-04
    Posts
    6

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    Thank you so much for your quick response. I will be out of the office until next week, but I will give it a try when I get back and let you know the results.

  8. #8
    Member
    Join Date
    2015-04
    Posts
    6

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    Opie,

    I had replied last weekend but just checked back and realized it didn't post for some reason. Your code edits were spot on! The routine works great now. One question, though, as I am pretty much code illiterate. To keep the figure lines on their original layers instead of changing to breakline, would it be as simple as removing all lines of code that referenced the "breakline" layer?

    Thanks again,

    Steve

  9. #9
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    Find the following four lines and place a semi-colon at the beginning of each line as shown below.
    Code:
    ;  (if (not (tblsearch "LAYER" strBreaklineLayer))
    ;    (_AddLayer strBreaklineLayer)
    ;  )
    ;  (vla-put-layer oFigure strBreaklineLayer)
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  10. #10
    Member
    Join Date
    2015-04
    Posts
    6

    Default Re: Convert Survey Figure and Feature Line to 2D Polyline

    Opie,

    The edits worked great. Thanks again for all your help!

    Steve

Page 1 of 2 12 LastLast

Similar Threads

  1. Double Click a Line to Convert it to a Polyline
    By zoomharis in forum AutoCAD Tips & Tricks
    Replies: 23
    Last Post: 2016-05-29, 09:21 PM
  2. Line Work (Survey Figure) Issue
    By dwknutson in forum AutoCAD Civil 3D - General
    Replies: 1
    Last Post: 2012-11-29, 02:46 PM
  3. Create an Alignment from a Survey Figure Line
    By Wish List System in forum Civil 3D Wish List
    Replies: 0
    Last Post: 2012-11-13, 03:02 PM
  4. Convert feature line to alignment/profile
    By civil3d.wishlist1941 in forum Civil 3D Wish List
    Replies: 0
    Last Post: 2010-10-06, 02:10 AM
  5. Convert an ARC to a Line or Polyline
    By nigel.chesworth in forum AutoCAD General
    Replies: 4
    Last Post: 2006-01-13, 10:02 PM

Posting Permissions

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