PDA

View Full Version : Solving Fractions



jawinthrop
2009-10-24, 02:33 PM
Ladies and Gents,

I am trying to automate coordinates from a previouse "cookis cutter" project. The instrumentation is all in the same location but the coordinates will change because it is a new unit. I started with the elevation and have gotten really close. I have been beating my head on the desk for a day know and know that there has to be an easier way to do this.

See the code I have thus far and thanks for any help.


;routines:
;;;;;;;cte - main routine
;;;;;;;get_text - retrieves all text lines
;;;;;;;findmatch - finds a match within the text lines
;;;;;;;modify_entity_list - updates the drawing database


;globally change elevation text ranging fromm "3530" to "3630"

(defun cte ()
;(command "-units" "2" "4" "1" "4" "0" "n")
(setq strmatch 0) ;number of string matches
(setq strchgd 0) ;number of strings changed
;(setq oldstrreal 3530) ;set first old real to search for
(setq oldstr "3530") ;set first old string to search for
;(setq oldintreal (atof oldstrreal)) ;convert old string to real

(setq oldint (atoi oldstr)) ;convert old string to integer
(while (< oldint 3630) ;set last old string to search for
;(setq newstr1 (rtos (- oldint 3434.5))) ;set replacement real
;(setq newstr2 (atof newstr1))
;(setq newstr (rtos (* 12 newstr2)))
;(setq newstr (rtos n(loadewreal)) ;convert replacement real to string
(setq newstr (itoa (- oldint 3434.6))) ;set replacement string
(get_text) ;find and fix all matching text in drawing
(setq oldint (1+ oldint))
(setq oldstr (itoa oldint))
;(command "-units" "4" "16" "1" "4" "0" "n")
);end while

(princ ss1len)
(princ " total text lines found")
(terpri)
(princ "Found ")
(princ strmatch)
(princ " text string matches between 3530 and 3630")
(terpri)
(princ "Changed ")
(princ strchgd)
(princ " text lines")
(terpri)

;(setq strmatch nil)
;(setq strchgd nil)
;(setq newstr1 nil)
;(setq newstr2 nil)
;(setq strchgd nil)
;(setq oldint nil)
;(setq newstr nil)
);end defun cte


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;Sub-Routine: get text per requests in cte routine;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun get_text ()
(setq ss1 (ssget "x" '((0 . "TEXT")))) ;get all text
(setq ss1Len (sslength ss1)) ;get number of text strings found
(setq Num 0) ;set which text string to evaluate

(repeat ss1Len
(setq Ent (ssname ss1 Num)) ;get the entity name
(setq Entlist (entget Ent)) ;get entity list
(setq TxtLine (cdr (assoc 1 Entlist))) ;get the whole string to evaluate
(setq TxtLineLen (strlen TxtLine)) ;get lenght of text line
(FindMatch) ;find a match within the TxtLine string
(setq Num (1+ Num))
);end repeat
(setq ss1 nil)
(setq ss1Len nil)
(setq Num nil)
(setq Ent nil)
(setq TxtLine nil)
);end get_text

;**********************************************
;************* Find the Match ****************
;**********************************************

(defun FindMatch ()
(setq osl (strlen oldstr))
(setq nsl (strlen newstr))
(setq Cnt 1) ;setq character counter to first character
(setq StringRead (substr TxtLine Cnt osl))
(repeat TxtLineLen
(if (= StringRead oldstr)
(progn
(setq strMatch (1+ strmatch))
(setq TxtLinep (substr TxtLine 1 (- Cnt 1))) ;get prefix of TxtLine string before the match
(setq TxtLines (substr TxtLine (+ Cnt 4))) ;get suffix of TxtLine string after the match
(setq NewString (strcat TxtLinep newstr TxtLines)) ;put together new text line
(modify_entity_list)
);end progn
(progn
(setq Cnt (1+ Cnt))
(setq StringRead (substr TxtLine Cnt osl))
);end progn
);end if
);end repeat
(setq osl nil)
(setq nsl nil)
(setq Cnt nil)
(setq StringRead nil)
(setq TxtLinep nil)
(setq TxtLines nil)
(setq TxtLineLen nil)
);end defun FindMatch

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;Sub-Routine: modify existing entity list ;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun modify_entity_list ()
(setq NewValue (cons 1 NewString))
(setq OldValue (assoc 1 Entlist))
(setq Entlist (subst NewValue OldValue Entlist)) ;substitue old info with new
(entmod Entlist) ;write modified list
(setq strchgd (1+ strchgd))
(setq NewString nil)
(setq NewValue nil)
(setq OldValue nil)
(setq Entlist nil)
);end modify_entity_list

jawinthrop
2009-10-24, 02:48 PM
Sorry, forgot to add that the that the old grade was 3538'-0" and the grade at the new unit is 103'-6". that is where the 3434.5 come in (3538-103.5=3434.5). I was successful with the 3434 but not the 3434.5.

RobertB
2009-10-26, 05:08 PM
Sorry, forgot to add that the that the old grade was 3538'-0" and the grade at the new unit is 103'-6". that is where the 3434.5 come in (3538-103.5=3434.5). I was successful with the 3434 but not the 3434.5.Your code is using integers. However, you are now dealing with reals. You need to revise the code to work with reals. Which it really should have been written to do in the first place.

jawinthrop
2009-10-27, 04:22 PM
Yes, your right. This has gotten a little messy on me. I think need to start over.