See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: Need some help 'strcat'ing parts of a sublist and replacing that into the original list

  1. #1
    Civil Engineering Moderator MHultgren's Avatar
    Join Date
    2000-12
    Location
    Central Iowa
    Posts
    1,425
    Login to Give a bone
    0

    Default Need some help 'strcat'ing parts of a sublist and replacing that into the original list

    I started with one of Peter's AU06 routines to create a table (TableMagic.LSP - great code Peter!)

    and what I need to do is combine list positions 3,4,&5 and 6,7 & 8, add some extra text to the string,
    then create a new list with the same position 1 & 2 entries and add the resultant strings to convert the original list from an 8 entity list to a 4 entity list

    Here is one line of the external text file I am working with:

    10176,0+00.00,37,49,56.35,109,58,0.98



    here is part of the code that I am trying to wrap my head around.

    Code:
    ; Utility to import a comma separated ascii text file into a list of sublists
    
    (defun UELS:CSVFiletoList (strFilename   ; String Filename
                               strChar       ; String Delimiter
                               /
                               lstOfSublists ; List of Sublists
                               strText       ; String of Delimited Strings
                               fil)          ; File ASCII Comma Separated Values
     (setq fil (open strFilename "r"))
     (while (setq strText (read-line fil))
      (setq lstOfSublists (cons (UELS:CSVStringToList strText strChar) lstOfSublists)))
      (close fil)
     (reverse lstOfSublists)
    )
    
    ; Parsing a textstring to a list.
    
    (defun UELS:CSVStringToList  (strText     ; String of Delimited strings
                                  strChar     ; String Delimiter
                                  /
                                  intPosition ; Integer String Character Index
                                  lstStrings) ; List of Strings
     (while (setq intPosition (vl-string-search strChar strText 0))
      (setq lstStrings  (cons (substr strText 1 intPosition) lstStrings)
            strText     (substr strText (+ intPosition 1 (strlen strChar)))))
     (reverse (cons strText lstStrings))
    )
    
    ;**************************************************************************************
    ;**************************************************************************************
    
    ;This function concatenates the Latitude and longitude values
    
    (defun UELS:LatLongComp (/ lstSublist)
      (setq strCompressLat (strcat "N" (nth 2 lstSublist) "\U+00B0" (nth 3 lstSublist) "\'" (nth 4 lstSublist) "\""))
      (setq strCompressLong (strcat "W" (nth 5 lstSublist) "\U+00B0" (nth 6 lstSublist) "\'" (nth 7 lstSublist) "\""))
    )
    Last edited by MHultgren; 2018-06-13 at 02:40 PM. Reason: add external text string sample
    Mark Hultgren
    Just a Lurker
    http://www.MKW-Ind.com
    Blog
    Socializing??

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,358
    Login to Give a bone
    1

    Default Re: Need some help 'strcat'ing parts of a sublist and replacing that into the original list

    In your UELS:LatLongComp sub-routine, add a list at the end to combine the two generated strings in the order you need. Then append the resulting list with a new list consisting of the first two elements of the initial list.
    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
    Civil Engineering Moderator MHultgren's Avatar
    Join Date
    2000-12
    Location
    Central Iowa
    Posts
    1,425
    Login to Give a bone
    0

    Default Re: Need some help 'strcat'ing parts of a sublist and replacing that into the original list

    Thanks Opie!
    Sometimes I just overthink things.
    Mark Hultgren
    Just a Lurker
    http://www.MKW-Ind.com
    Blog
    Socializing??

  4. #4
    Civil Engineering Moderator MHultgren's Avatar
    Join Date
    2000-12
    Location
    Central Iowa
    Posts
    1,425
    Login to Give a bone
    0

    Default Re: Need some help 'strcat'ing parts of a sublist and replacing that into the original list

    OK Opie,
    This is what I have so far, but I am getting an error: bad Function in Expression.
    What am I missing?

    This is inside
    (mapcar 'lambda (lstSublist

    Code:
    (list (nth 0 lstSublist)
    		    (nth 1 lstSublist)
    		    (strcat ("N" (nth 2 lstSublist)
    				 (itoa "\%%d")
    				 (nth 3 lstSublist)
    				 "\'"
    				 (nth 4 lstSublist)
    				 "\'\'"
    			    )
    		    )
    		     (strcat ("W" (nth 5 lstSublist)
    				 (itoa "\%%d")
    				 (nth 6 lstSublist)
    				 "\'"
    				 (nth 7 lstSublist)
    				 "\'\'"
    			    )
    		    )
    	      )
    Mark Hultgren
    Just a Lurker
    http://www.MKW-Ind.com
    Blog
    Socializing??

  5. #5
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,358
    Login to Give a bone
    0

    Default Re: Need some help 'strcat'ing parts of a sublist and replacing that into the original list

    You mentioned previously this consisted all of strings. Why are you using the itoa function to convert a string, "\%%d", to a string? It only works for converting integers to strings. Once that is corrected, you will need to look at your argument for the strcat function. You are supplying a set of parenthesis for each, which do not return a string. The strcat function expects a string.

    Try this:
    Code:
    	   (list (nth 0 lstSublist)
    		 (nth 1 lstSublist)
    		 (strcat "N" (nth 2 lstSublist)
    				 "\%%d"
    				 (nth 3 lstSublist)
    				 "\'"
    				 (nth 4 lstSublist)
    				 "\'\'"
    			    
    		    )
    		 (strcat "W" (nth 5 lstSublist)
    				 "\%%d"
    				 (nth 6 lstSublist)
    				 "\'"
    				 (nth 7 lstSublist)
    				 "\'\'"
    			    
    		    )
    	      )
    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

  6. #6
    Civil Engineering Moderator MHultgren's Avatar
    Join Date
    2000-12
    Location
    Central Iowa
    Posts
    1,425
    Login to Give a bone
    0

    Default Re: Need some help 'strcat'ing parts of a sublist and replacing that into the original list

    Thanks Opie,
    Been a few years since I did anything with LISP and needed to build something quick and easy for users.
    Mark Hultgren
    Just a Lurker
    http://www.MKW-Ind.com
    Blog
    Socializing??

Similar Threads

  1. Make parts keep their original family properties
    By Wish List System in forum Revit Structure - Wish List
    Replies: 0
    Last Post: 2013-11-10, 08:25 AM
  2. Parts From the CC Display Modified Lengths in Parts List
    By Inventor Wishes in forum Inventor Wish List
    Replies: 2
    Last Post: 2012-12-19, 04:16 AM
  3. Parts List Styles and Extents available in Parts List
    By Inventor Wishes in forum Inventor Wish List
    Replies: 0
    Last Post: 2009-06-19, 02:13 PM
  4. Adding Metric Parts in Parts List?
    By Keefe_Lee_G-and-O in forum AutoCAD Civil 3D - Pipes
    Replies: 1
    Last Post: 2008-08-19, 12:54 PM
  5. strcat
    By fletch97 in forum AutoLISP
    Replies: 6
    Last Post: 2005-07-18, 06:29 PM

Tags for this Thread

Posting Permissions

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