TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Krushert on July 08, 2006, 07:43:44 AM

Title: Pulling information from a Field
Post by: Krushert on July 08, 2006, 07:43:44 AM
Hello all,

I need some advice on fields to see if they can work in my automated plotting of PDFs.  I really know very little of what a field can do.  Spending a little time researching has shown that fields can pull information from some source.  What I want to do is reverse that and pull information from the field itself. 

Let me explain on what I am doing.  I have been using a lisp routines that I have created to speed up the plotting process.  (I don’t like batch plotting).  Since Autodesk finally come to their senses and included a PDF writer (IMHO worth the $500 subscription price) into the R2007, I can do (attempt) what I been wanting to do for a long time.   I want to pull the Drawing Number from our title block and feed that to the PDF writer when it asks for a name and a location.  The drawing number is the common denominator in all of my user projects.   File names change suit the needs of all the various types of projects we do and Layout tabs names are unreliable because of the users.

Can I use Fields to do this?  Fields are Mtext which is exactly what we use now for drawing numbers.   We xref our title blocks and use Mtext for the Drawing number, title and scale.  Would using an attribute be easier? 

Thanks in advance.
Title: Re: Pulling information from a Field
Post by: DEVITG on July 08, 2006, 06:21:14 PM
Maybe if your dwg number [dwg#] is allways at the same location , you gan get it with a SSGET .

(setq dwg# (ssget (list xpt ypt)))

Also if your dwg# as a common prefix, and any other unique feature ,as the layer, linetype,textstyle or so,  it can be also get by a SSGET

(setq dwg#( ssget "x" (list (cons 0 "METEXT" ) (CONS 62 "DWG#COLOR") (CONS 8 "DWG#LAYER) (CONS 1 "DWG#*) (CONS 10 "DWG#INSERTIONPOIT) )))

(CONS 1 "DWG#*) will get any MTEXT that beguin with DWG#, and as it is only one MTEX that beguin with such prefix, it will pick it

Hope it help

Title: Re: Pulling information from a Field
Post by: Krushert on July 12, 2006, 09:58:25 AM
Maybe if your dwg number [dwg#] is allways at the same location , you gan get it with a SSGET .

(setq dwg# (ssget (list xpt ypt)))

Also if your dwg# as a common prefix, and any other unique feature ,as the layer, linetype,textstyle or so,  it can be also get by a SSGET

(setq dwg#( ssget "x" (list (cons 0 "METEXT" ) (CONS 62 "DWG#COLOR") (CONS 8 "DWG#LAYER) (CONS 1 "DWG#*) (CONS 10 "DWG#INSERTIONPOIT) )))

(CONS 1 "DWG#*) will get any MTEXT that beguin with DWG#, and as it is only one MTEX that beguin with such prefix, it will pick it

Hope it help

Sorry I did not get back sooner.  I had one of those “we work all weekend and all night because they screwed up on schedule” projects.

You are saying to use DXF codes on the Mtext.  cool.  Never used it before but there is always a first.

Due to our loosey goosey standards, our users will have tweak the location or prefix due to the particular project.  Most of our drawings are have a prefix “A####” until we get to the cover page or if we do our own structural drawings.  The only option that I could use would be to change the DWG#’s layer to different layer.  Another thought is to change the color from ByLayer to different color.   But that means changing all the current drawings to this new “standard”.

What DXF code reads and returns the contents of Mtext?
Thanks  :-)
Title: Re: Pulling information from a Field
Post by: CAB on July 12, 2006, 12:05:44 PM
Code: [Select]
(CONS 1 "DWG#*)
In you example use this with the example above (CONS 1 "A####") and will return only the mtext with a WCMATCH of
"A" plus four number characters.
Title: Re: Pulling information from a Field
Post by: DEVITG on July 12, 2006, 12:53:38 PM
I have a type error here

(setq dwg#( ssget "x" (list (cons 0 "METEXT" ) (CONS 62 "DWG#COLOR") (CONS 8 "DWG#LAYER) (CONS 1 "DWG#*) (CONS 10 "DWG#INSERTIONPOIT) )))

It shall be so.

(cons 0 "MTEXT")

Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 09:06:32 AM
Code: [Select]
(CONS 1 "DWG#*)
In you example use this with the example above (CONS 1 "A####") and will return only the mtext with a WCMATCH of
"A" plus four number characters.

Sorry CAB that want work. Take a look at the pictures.  Our drawing prefixes change with the type of sheet it is placed on.  For example, TP for Title page.  And the number of characters change too.  It is always in a general location, but the actual insert point could vary depeding on the nuiances of the user doing the inserting and/or it could be two lines (word wrap) of text
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 10:03:55 AM
Well be creative in your approach. 8-)
Expanding on DEVITG's example:

Code: [Select]
(setq dwg# ( ssget "x" (list (cons 0 "MTEXT" )  (cons 8 "DWG#LAYER) (cons 1 "A#*,TP") )))
Where (cons 1 "A#*,TP") will WCMATCH any mtext that starts with a capital 'A' followed by one number and anything that may follow.
AND any mtext that has only the capital 'TP' as its value.

The example above uses only LAYER to narrow the selection. You may want to add more restrictions.
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 10:47:54 AM
Well be creative in your approach. 8-)
Expanding on DEVITG's example:
Code: [Select]
(setq dwg# ( ssget "x" (list (cons 0 "MTEXT" )  (cons 8 "DWG#LAYER) (cons 1 "A#*,TP") )))

Where (cons 1 "A#*,TP") will WCMATCH any mtext that starts with a capital 'A' followed by one number and anything that may follow.  AND any mtext that has only the capital 'TP' as its value.
I am leary of using this approach because all the different types of prefixes:  S's, APs, the list goes on.

The example above uses only LAYER to narrow the selection. You may want to add more restrictions.
Aha now I am seeing how this is working.  What is the code fof Mtext height? The text height is inserted at 5/8" in height.  Just to make make not so restrictive, can I have some filtering?  For example, (cons ?? "9/16<*>11/16").  The  DWG# is the only text that is 5/8". 

This brings up another question, will this search both model space and paperspace? or just current space?
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 11:05:09 AM

Code: [Select]
.... ( ssget "x" (list ......
When the routine reads this; what will it do?
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 11:19:57 AM
You need to decide weather there is enough unique properties of the mtext to be able to reliably find it in the drawing.

So please list it's unique properties:
Layer
Style
Text Height is not usable in mtext but ok for dtext
Color if not 'By Layer', must be an override
Insert Point - you ruled this out
Text String - varies
space - paper or model or current

More on text string, if the text is unique you can often use wcmatch to filter for it.

You need to explore ssget filters and wcmatch.

And in the end this may not be a viable solution for your problem but I suspect it is.
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 11:31:35 AM
From the help file
Quote
Creates a selection set from the selected object
(ssget [sel-method] [pt1 [pt2]] [pt-list] [filter-list])

Selection sets can contain objects from both paper and model space, but when the selection set is used in an operation, ssget filters out objects from the space not currently in effect. Selection sets returned by ssget contain main entities only (no attributes or polyline vertices).

Arguments

sel-method

A string that specifies the object selection method. Valid selection methods are:
C  Crossing selection.
CP  Cpolygon selection (all objects crossing and inside of the specified polygon).
F  Fence selection.
I  Implied selection (objects selected while PICKFIRST is in effect).
L  Last visible object added to the database.
P  Last selection set created.
W  Window selection.
WP  WPolygon (all objects within the specified polygon).

X  Entire database. If you specify the X selection method and do not provide a filter-list, ssget selects all entities in the database, including entities on layers that are off, frozen, and out of the visible screen.
:E  Everything within the cursor's object selection pickbox.
:N  Call ssnamex for additional information on container blocks and transformation matrices for any entities selected during the ssget operation. This additional information is available only for entities selected via graphical selection methods such as Window, Crossing, and point picks.

Unlike the other object selection methods, :N may return multiple entities with the same entity name in the selection set. For example, if the user selects a subentity of a complex entity such as a BlockReference, PolygonMesh, or old style polyline, ssget looks at the subentity that is selected when determining if it has already been selected. However,  ssget actually adds the main entity (BlockReference, PolygonMesh, etc.) to the selection set. The result could be multiple entries with the same entity name in the selection set (each will have different subentity information for ssnamex to report).

:S   Allow single selection only.

Some examples

(ssget "X")    ; get the entire database
(ssget "ALL") ; filters out frozen layers

;;  Limit the _X filter to current tab model space which ever is active
(setq ss (ssget "x" (list (cons 410 (getvar "ctab")))))
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 11:48:22 AM
You need to decide weather there is enough unique properties of the mtext to be able to reliably find it in the drawing.
So please list it's unique properties: 

Layer  see code
Style   I could use this
Text Height is not usable in mtext but ok for dtext  Just an Idea
Color if not 'By Layer', must be an override  Color is Bylayer
Insert Point - you ruled this out  Correct but how about general position  see code
Text String - varies   correct.  we pdf everything and we create special docs for whomever for example there is now a conversation pertaining to Condo Docs.
space - paper or model or current  I "want" paperspace.  if my user places a titleblock in the model, he can pdf the old fashion way and afterwards, I will have more painfull torture for him/her.  :pissed:[/quote]

You need to explore ssget filters and wcmatch. 
  Currently going down this path, and I think i found something.
And in the end this may not be a viable solution for your problem but I suspect it is.
  I suspect too.  and if not, no big deal because I am having fun trying to figure it out.

This is what I got so far.  Tested and return a "nil" for "dwg#".
Code: [Select]
(defun c:dwg ()
  (vl-cmdf ".undo" "m")
  (setq dwg#
(ssget "_W" '(0 0) '(5 5)
(list
  (CONS 0 "MTEXT")
  (CONS 8 "TITLE-BLOCK-TEXT")
  )
)
)
  )
Title: Re: Pulling information from a Field
Post by: T.Willey on July 13, 2006, 11:59:01 AM
One problem with window or crossing, is that the area you are using has to be on screen.  In other words if you don't see the lower right hand corner of your title block, it won't select anything.

/back to regularly scheduled program.
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 12:06:44 PM
oops! wrong coodinates in code.  now I get "<Selection set: 4d1>"


One problem with window or crossing, is that the area you are using has to be on screen.  In other words if you don't see the lower right hand corner of your title block, it won't select anything.

/back to regularly scheduled program.

Hmmm this makes me think. 
The Existing Routine that I will be modifing with this excerise performs a "Zooms-Extents".  So I dont think it will be a problem.  But I dont know if I want to rely on that.  Something is making me itch about that.
Title: Re: Pulling information from a Field
Post by: T.Willey on July 13, 2006, 12:09:26 PM
Another option is to search for all the mtext objects on that layer, and then sort the selection set by coordinates.  If text you want is always the right most, and lowest text then it can be easy.  I have done this before.

< sorry if stepping on any toes >
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 12:13:54 PM
I have steel toed construction boots.  :lmao:

And appreciate all the help I can get. 8-)
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 12:27:48 PM
I have steel toed construction boots.  :lmao:

And appreciate all the help I can get. 8-)

I need all the help I can get too.  But when you say it Cab, one could think that you you need a help in teaching me because I am so slow.   :lmao:
Title: Re: Pulling information from a Field
Post by: T.Willey on July 13, 2006, 12:31:44 PM
Maybe posting a filled out title block would be best, then we can see what would be the best way to search for your information.
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 12:44:20 PM
I need all the help I can get too.  But when you say it Cab, one could think that you you need a help in teaching me because I am so slow.   :lmao:

I hope no one took it that way :-)

Try listing out all the sheet label options:
A1 - A99
S1 - S99
TP
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 12:48:47 PM
Maybe posting a filled out title block would be best, then we can see what would be the best way to search for your information.

Actually I just found it .  The Text Style.  The Drawing number has a unique text.  Ah I am going to say is my fearless leader created the title block.  Normally he creates more work but this time he inadvertly help me (us).  If I confine the search to just paper space and the text style I should come with the just the data for the drawing number.
see code. 
Code: [Select]
(defun c:dwg ()
  (vl-cmdf ".undo" "m")
  (setq SS
(ssget "_x"
(list
  (cons 410 (getvar "ctab"))
  (cons 0 "MTEXT")
  (cons 7 "helv-meds-19")
  (CONS 8 "TITLE-BLOCK-TEXT")
)
)
  )
)

Since I like to fish, I know I caught some data but I don't know what kind of fish (data) it is and how do I cook it (pull the drawing number from it).  :-)
Title: Re: Pulling information from a Field
Post by: T.Willey on July 13, 2006, 12:55:04 PM
Once you get the entity name, then use entget to get the entity's code, then look at dxf code 1.
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 01:07:51 PM
Potential problem with this:
(cons 410 (getvar "ctab"))
You must be in that active tab for it to work. If you are in Model space tab, no good.
Or if you are in a tab without a title block, no good.

If you know the name of the tab:
(cons 410 "tabname")
or this if you know the first letter
(cons 410 "N*")


So you may eant to remove that & then check the item to see if it is in paper space.
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 01:59:07 PM
Once you get the entity name, then use entget to get the entity's code, then look at dxf code 1.

It took me awhile to get this.  I went fishing in the help section and came up with this.  Though I really dont know "how" it is doing it.
Code: [Select]
(defun c:dwg ()
  (vl-cmdf ".undo" "m")
  (setq ss
(ssget "_x"
(list
  (cons 410 (getvar "ctab"))
  (cons 0 "MTEXT")
  (cons 7 "helv-meds-19")
  (CONS 8 "TITLE-BLOCK-TEXT")
)
)
  )
  (setq name (ssname SS 0))
  (setq code (cdr (entget name)))
)

and it return this for the entget.
Code: [Select]
Command: dwg ((0 . "MTEXT") (330 . <Entity name: 7ebfad40>) (5 . "47F") (100 .
"AcDbEntity") (67 . 1) (410 . "Layout1") (8 . "TITLE-BLOCK-TEXT") (100 .
"AcDbMText") (10 34.0938 1.54018 0.0) (40 . 0.625) (41 . 2.01297) (46 . 0.0)
(71 . 5) (72 . 5) (1 . "{\\T0.9;A1.02}") (7 . "helv-meds-19") (210 0.0 0.0 1.0)
(11 1.0 0.0 0.0) (42 . 1.68555) (43 . 0.638021) (50 . 0.0) (73 . 1) (44 . 0.75))

Command: 'VLIDE

and you said take a look at dxf code 1
Code: [Select]
(1 . "{\\T0.9;A1.02}")
Title: Re: Pulling information from a Field
Post by: T.Willey on July 13, 2006, 02:11:26 PM
Code: [Select]
(cdr (assoc 1 (entget name)))

Now you will have to look at the formating strings for Mtext, so that you will only get the text itself and not all the formating.  This is available in the help docs.
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 03:37:16 PM
Now you will have to look at the formating strings for Mtext, so that you will only get the text itself and not all the formating.  This is available in the help docs.

I give up, not finding it in help and I briefly look in the waters of the swamp.  The closest I could find is the Section "Format Multiline Text".  It tells me how to add formating to text but not on removing it.  Could you point me right direction of #$%@ Help Docs.

It took me sometime to figure out on how the formation got there in the first place.  I am the culprit.  Typically we use a 3 characters dwg number, but the project that I am currently assign to is so large. I had to go to a 4 characters dwg# and reduce the spacing between characters.
Title: Re: Pulling information from a Field
Post by: T.Willey on July 13, 2006, 03:41:41 PM
You are in the right spot.  It tells you how to add it, so now you know what to look for.  Here is a quick one I wrote.  It might get you going on the right path.  There is also code floating around the net for removing mtext formatting.  If you find one, you can steal (borrow) the portion needed to do your code.
Code: [Select]
(defun StripString (String / cstr1 cstr2 nString cnt1 tstr1)
; Strips out formation for color, font, height and width.

(setq cnt1 1)
(while (and (setq cstr1 (substr String 1 1)) (> (strlen String) 0))
 (if (= cstr1 "\\")
  (progn
   (setq cstr2 (substr String 2 1))
   (if (member (strcase cstr2) '("C" "F" "H" "W"))
    (progn
     (while (/= (substr String cnt1 1) ";")
      (setq cnt1 (1+ cnt1))
     ); while
     (setq String (substr String (1+ cnt1) (strlen String)))
     (setq cnt1 1)
    ); progn
    (progn
     (if nString
      (setq nString (strcat nString (substr String 1 1)))
      (setq nString (substr String 1 1))
     ); if
     (setq String (substr String 2 (strlen String)))
    ); progn
   ); if
  ); progn
  (progn
   (if nString
    (setq nString (strcat nString (substr String 1 1)))
    (setq nString (substr String 1 1))
   ); if
   (setq String (substr String 2 (strlen String)))
  ); progn
 ); if
); while
(setq tstr1 (vl-string->list nString))
(if (and (not (member 92 tstr1)) (member 123 tstr1))
 (setq tstr1 (vl-remove-if '(lambda (x) (or (= x 123) (= x 125))) tstr1))
); if
(vl-list->string tstr1)
)
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 03:53:51 PM
Another stripper 8-)

http://www.theswamp.org/index.php?topic=7272.0
Title: Re: Pulling information from a Field
Post by: T.Willey on July 13, 2006, 03:56:36 PM
Another stripper 8-)
You just wanted to say that.....
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 04:22:14 PM
Yes  :-D

OK try this.
If you use the 410 you will not need the 67.
If you use the 67 then it will get all layouts if more than one.

Code: [Select]
(defun c:dwg ()
  (vl-cmdf ".undo" "m")
  (if
       (setq  ss
              (ssget "_x"
                       (list
                         (cons 0 "MTEXT")
                         (cons 7 "helv-meds-19")
                         (CONS 8 "TITLE-BLOCK-TEXT")
                         (cons 410 (getvar "ctab"))
                         ;'(67 . 1) ; in paper space but if you have >1 tab
                         '(-4 . ">=,>=,*")'(10 0.0 0.0 0.0)
                         '(-4 . "<=,<=,*")'(10 5.0 5.0 0.0)
                       )
              )
       )
    (progn
      (setq txt (cdr (assoc 1 (entget (ssname SS 0)))))
      (setq txt (strip txt)) ; use a mtext code stripper
    )
  )
)
Title: Re: Pulling information from a Field
Post by: Krushert on July 13, 2006, 04:37:36 PM
:-o :-o :-o :-o :-o
 :cry: :cry: :cry: :cry: :cry:

All three suggested codes are huge for just formation that "should not" be there in the first place.   I still have to plunk it into my existing code.
Makes me rethink things again.
Title: Re: Pulling information from a Field
Post by: CAB on July 13, 2006, 05:40:51 PM
Well it may be easier to modify the mtext to make the sheet number reliable.
Your choices are as you listed in you first post as well as plain text.
The problem with mtext as you have discovered is the use of formatting characters.
What ever you choose is up to you & how your drafters will adapt to the change.
As for the amount of code, that is a small price to pay for getting the job done
in a timely manner. SO I don't see the volume of code being the criterion for
consideration of which method to use. I would be more concerned with the impact
on the staff & production both short & long term.

My 2 cents. :-)
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 07:55:14 AM
Well it may be easier to modify the mtext to make the sheet number reliable.
Your choices are as you listed in you first post as well as plain text.
The problem with mtext as you have discovered is the use of formatting characters.
What ever you choose is up to you & how your drafters will adapt to the change.
As for the amount of code, that is a small price to pay for getting the job done
in a timely manner. SO I don't see the volume of code being the criterion for
consideration of which method to use. I would be more concerned with the impact
on the staff & production both short & long term.

My 2 cents. :-)

Thanks for your 2 Cents Cab.  :-)
I really do appreciate people’s opinions and takes on things and I make a habit of listening.  Never know what you can learn.

I had to drive to up to a race just to get a taste of defeat.  So on the way back I did some thinking about this routine.  I came to same thing as you have listed.  My realization is the whole human factor, you can count on it to throw you a curve ball.  My users (half of them being Architect Interns) will have their opinions on how an item should look like.  So therefore they are going to tweak the Mtext for either legitimate reasons or not.  So it is better to have a code to anticipate that. 

Thanks
Title: Re: Pulling information from a Field
Post by: CAB on July 14, 2006, 08:22:12 AM
If it were me I would most likely use a block with attributes for the  Drawing number, title and scale.
Title: Re: Pulling information from a Field
Post by: Sdoman on July 14, 2006, 08:36:30 AM

 Would using an attribute be easier? 


Much easier imo.  Using an attribute, you can easily extract the sheet number data and not have to deal with mtext formatting. Even easier is using an attribute that displays the layout name. 

Either of the expressions below should work for displaying the layout name, depending on your AutoCAD version.  The first expression below is what I've been using since 2005, the second expression wasn't available at that time.

%<\AcDiesel $(getvar,ctab)>%
 - or -
%<\AcVar ctab>%

Now name the layout tabs to whatever you want your sheets to be named.  The sheet number attribute will update automagically.  When you plot to file, AutoCAD will append the layout name to the drawing name and use that for the plot file name.  You can accept that plot file name, or manually or programmatically use another name.

Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 09:34:01 AM
If it were me I would most likely use a block with attributes for the  Drawing number, title and scale.

We just went through a major change to xref the titile block to quell the whining of clunkieness of the previous Title Block that was extremly bloated with attruibutes and I agree with them.  The think I like about using mtext vs attrubites is the mtext you can have multilple lines of text in one enity.  An it is something familiar to my users.

Steved

If I understand you correctly, are you having the layout tab copy the drawing number and the user edits the drawing number? Or is it the other way around?
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 09:38:25 AM
I am getting this at the command line
Quote
Command: 'VLIDE
Command:
Command: dwg .undo Current settings: Auto = On, Control = All, Combine = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: m
Command:
Command:
Command:
Command: too few arguments
Command: 'VLIDE

and getting this in the watch window
Quote
LOG Watch
...............
DWG# = nil
SS = <Selection set: 26>
TXT = "{\\T0.9;A1.02}"

Code Attached
Code: [Select]
(defun c:dwg ()
  (vl-cmdf ".undo" "m")

;;;=======================[ Strip_Text.lsp ]=============================
;;; Author:  Charles Alan Butler Copyright© 2005
;;; Version: 2.2  Oct. 19, 2005
;;; Purpose: Strip format characters from text or mtext
;;; Returns: A string 
;;; Sub_Routines: -None
;;; Arguments: A string variable
;;;======================================================================

(defun strip_text (str / skipcnt ndx newlst char fmtcode lst_len
                   IS_MTEXT LST  NEXTCHR PT TMP)

  (setq ndx 0
        ;; "fmtcode" is a list of code flags that will end with ;
        fmtcode
         (vl-string->list "CcFfHhTtQqWwAa") ;("\C" "\F" "\H" "\T" "\Q" "\W" "\A")
  )
  (if (/= str "") ; skip if empty text ""
    (progn
      (setq lst      (vl-string->list str)
            lst_len  (length lst)
            newlst   '()
            is_mtext nil ; true if mtext
      )
      (while (< ndx lst_len)
        ;; step through text and find FORMAT CHARACTERS
        (setq char    (nth ndx lst) ; Get next character
              nextchr (nth (1+ ndx) lst)
              skipcnt 0
        )

        (cond
          ((and (= char 123) (= nextchr 92)) ; "{\" mtext code
           (setq is_mtext t
                 skipcnt 1
           )
          )

          ((and (= char 125) is_mtext) ; "}"
           (setq skipcnt 1)
          )


          ((= char 37) ; code start with "%"
           (if (null nextchr) ; true if % is last char in text
             (setq skipcnt 1)
             ;;  Dtext codes
             (if (= nextchr 37) ; %% code found
               (if (< 47 (nth (+ ndx 2) lst) 58) ; is a number
                 ;;number found so fmtcode %%nnn
                 (setq skipcnt 6)
                 ;; else letter code, so fmtcode %%p
                 (setq skipcnt 4)
               ) ; endif
             ) ; endif
           ) ; endif
          ) ; end cond (= char "%"))


          ((= char 92) ; code start with "\"
           ;;  This section processes mtext codes

           (cond
             ;; Process Coded information
             ((null nextchr) ; true if \ is last char in text
              (setq skipcnt 1)
             ) ; end cond 1

             ((member nextchr fmtcode) ; this code will end with ";"
              ;; fmtcode -> ("\C" "\F" "\H" "\T" "\Q" "\W" "\A"))
              (while (/= (setq char (nth (+ skipcnt ndx) lst)) 59)
                (setq skipcnt (1+ skipcnt))
              )
              (setq skipcnt (1+ skipcnt))
             ) ; end cond


             ;; found \U then get 7 character group
             ((= nextchr 85) (setq skipcnt (+ skipcnt 8)))

             ;; found \M then get 8 character group
             ((= nextchr 77) (setq skipcnt (+ skipcnt 9)))

             ;; found \P then replace with CR LF 13 10
             ;;  debug do not add CR LF, just remobe \P
             ((= nextchr 80) ; "\P"
              (setq newlst  (append newlst '(32))
                    ;ndx     (+ ndx 1)
                    skipcnt 2
              )
             ) ; end cond


             ((= nextchr 123) ; "\{" normal brace
              (setq ndx (+ ndx 1))
             ) ; end cond

             ((= nextchr 125) ; "\}" normal brace
              (setq ndx (+ ndx 1))
             ) ; end cond

             ((= nextchr 126) ; "\~" non breaking space
              (setq newlst (append newlst '(32))) ; " "
              (setq skipcnt 2) ; end cond 9
             )

             ;; 2 character group \L \l \O \o
            ((member nextchr '(76 108 79 111))
              (setq skipcnt 2)
             ) ; end cond

             ;;  Stacked text format as "[ top_txt / bot_txt ]"
             ((= nextchr 83) ; "\S"
              (setq pt  (1+ ndx)
                    tmp '()
              )
              (while
                (not
                  (member
                    (setq tmp (nth (setq pt (1+ pt)) lst))
                    '(94 47 35) ; "^" "/" "#" seperator
                  )
                )
                 (setq newlst (append newlst (list tmp)))
              )
              (setq newlst (append newlst '(47))) ; "/"
              (while (/= (setq tmp (nth (setq pt (1+ pt)) lst)) 59) ; ";"
                (setq newlst (append newlst (list tmp)))
              )
              (setq ndx     pt
                    skipcnt (1+ skipcnt)
              )
             ) ; end cond


           ) ; end cond stmt  Process Coded information
          ) ; end cond  (or (= char "\\")

        ) ; end cond stmt
        ;;  Skip format code characters
        (if (zerop skipcnt) ; add char to string
          (setq newlst (append newlst (list char))
                ndx    (+ ndx 1)
          )
          ;;  else skip some characters
          (setq ndx (+ ndx skipcnt))
        )

      ) ; end while Loop
    ) ; end progn
  ) ; endif
  (vl-list->string newlst) ; return the stripped string
) ; end defun
;;;======================================================================

  (setq ss
(ssget "_x"
(list
  (cons 410 (getvar "ctab"))
  (cons 0 "MTEXT")
  (cons 7 "helv-meds-19")
  (CONS 8 "TITLE-BLOCK-TEXT")
)
)
  )
  (setq txt (cdr (assoc 1 (entget (ssname SS 0)))))
  (setq txt (strip_text));;Mtext Formating Code Stripper
)
Title: Re: Pulling information from a Field
Post by: Sdoman on July 14, 2006, 10:00:46 AM

Steved

If I understand you correctly, are you having the layout tab copy the drawing number and the user edits the drawing number? Or is it the other way around?

The title block drawing contains an attribute with field as I described earlier.  We never edit this attribute.  We edit the layout tab name to be the sheet number. The titleblock can be Xref'd or not, works either way.
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 10:16:02 AM
I am getting this at the command line

and getting this in the watch window

Code Attached

Never mind figured it out.
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 11:22:58 AM
Now it my principals that are screwing me over  :x :x :x

I thought we had it.

Code: [Select]
(cons 7 "helv-meds-19" "helv14")
I need search data for EITHER "helv-meds-19" OR "helv14".  Can this be done?  Please point me in the right direction.

My glorious principles and them having each their own titleblock have rolled me again.   :realmad: :realmad:  They cant agree on a common title block. arrggg  And they have to have separate text styles.  This has been going since the 5 years that I have been here.

I tried something similar to this "Filtering for Extended Data" section of Help.  Was getting too many arguments or bad arguments.
Quote
(ssget "X" '((0 . "CIRCLE") (-3 ("APP1,APP2"))))
Title: Re: Pulling information from a Field
Post by: T.Willey on July 14, 2006, 12:18:00 PM
I need search data for EITHER "helv-meds-19" OR "helv14".  Can this be done?  Please point me in the right direction.

Yes.  I think you would need to have it look like
Code: [Select]
(setq ss
 (ssget
  '(
   (0 . "MTEXT")
   (-4 . "<OR")
    (7 . "helv-meds-19")
    (7 . "helv14")
   (-4 . "OR>")
  )
 )
)
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 01:35:12 PM
What is the difference between the dots "." and the "cons"?
Where would I use one over the other?
Title: Re: Pulling information from a Field
Post by: T.Willey on July 14, 2006, 02:01:09 PM
What is the difference between the dots "." and the "cons"?
Where would I use one over the other?
The use of cons in generally used when you are making an associated list [ (0 . 0) ] and have a variable.  So
(0 . "MTEXT")
is the same as
(cons 0 "MTEXT")

Hope that makes sense.
Title: Re: Pulling information from a Field
Post by: CAB on July 14, 2006, 02:40:51 PM
Why not?
Code: [Select]
(cons 7 "helv-meds-19,helv14")
Title: Re: Pulling information from a Field
Post by: CAB on July 14, 2006, 02:54:45 PM
(quote exp)  Returns an expression without evaluating it.
_$ (quote (8 . "0"))
(8 . "0")

And a single quotation mark is the shorthand for quote.
_$ ' (8 . "0")
(8 . "0")

Where as (cons itm1 itm2)  constructs a dotted list when itm2 is an atom.
_$ (cons 8  "0")
(8 . "0")


If itm1 or itm2 is a variable you need to use cons because the variable needs to be evaluated.
_$ (setq var "abc")
"abc"
_$ (cons 8 var)
(8 . "abc")
_$ (quote (8 . var))
(8 . VAR)
_$ '(8 . var)
(8 . VAR)
Title: Re: Pulling information from a Field
Post by: T.Willey on July 14, 2006, 03:05:53 PM
Why not?
Code: [Select]
(cons 7 "helv-meds-19,helv14")
I thought about that, but then I thought it wouldn't work for some strange reason.  It has been a weird day at work for me.
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 03:41:58 PM
Okay this is what I am getting so far with "this" code.  clunky I know.

Tim your dotted pair threw me for a loop.  minor loop was the "x".  Then major one was the 410 & ctab variable.  I could not work it in.  If the current tab was 3rd tab of (3) layout tabs it return the first tab.  So I am came up with this. 

Code: [Select]
(setq ss1
       (ssget "_x"
      (list
(cons 0 "MTEXT")
(CONS 8 "TITLE-BLOCK-TEXT")
(cons 410 (getvar "ctab"))
      )
       )
)


  (setq ss2
       (ssget "p"
      '(
(-4 . "<OR")
(7 . "helv-meds-19")
(7 . "helv14")
(-4 . "OR>")
       )
       )
)
 
(setq txt (cdr (assoc 1 (entget (ssname ss2 0)))))
(setq dwg# (strip_text txt)) ;;Mtext Formating Code Stripper
)

Hey it works, until I go to the other Principal's title block with "helv14".  It crashes and returns this at the command line.
Quote
Command: bad argument type: lselsetp nil
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 03:43:59 PM
Why not?
Code: [Select]
(cons 7 "helv-meds-19,helv14")
I thought about that, but then I thought it wouldn't work for some strange reason.  It has been a weird day at work for me.

I tried that earlier but it crashed.  I will try it again with your formating. Maybe I didn't have it quite right.
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 03:54:57 PM
Why not?
Code: [Select]
(cons 7 "helv-meds-19,helv14")
I thought about that, but then I thought it wouldn't work for some strange reason.  It has been a weird day at work for me.

I tried that earlier but it crashed.  I will try it again with your formating. Maybe I didn't have it quite right.

Okay it work in the  "helv-meds-19" title block but not in the "helv14" title block.  Bck to find to why not.  I know it worked earlier.  I think. :? :? :?
Title: Re: Pulling information from a Field
Post by: T.Willey on July 14, 2006, 03:57:02 PM
These two should be in on ssget filter.
Code: [Select]
(setq ss1
       (ssget "_x"
      (list
(cons 0 "MTEXT")
(CONS 8 "TITLE-BLOCK-TEXT")
(cons 410 (getvar "ctab"))
      )
       )
)


  (setq ss2
       (ssget "p"
      '(
(-4 . "<OR")
(7 . "helv-meds-19")
(7 . "helv14")
(-4 . "OR>")
       )
       )
)
Would look like.
Code: [Select]
(setq ss1
       (ssget "_x"
      (list
(cons 0 "MTEXT")
(CONS 8 "TITLE-BLOCK-TEXT")
(cons 410 (getvar "ctab"))
'(-4 . "<OR")
'(7 . "helv-meds-19")
'(7 . "helv14")
'(-4 . "OR>")
       )
       )
)
or
Code: [Select]
(setq ss1
       (ssget "_x"
      (list
(cons 0 "MTEXT")
(CONS 8 "TITLE-BLOCK-TEXT")
(cons 410 (getvar "ctab"))
(cons -4  "<OR")
(cons 7  "helv-meds-19")
(cons 7  "helv14")
(cons -4  "OR>")
       )
       )
)
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 04:19:20 PM
Code: [Select]
(setq ss1
       (ssget "_x"
      (list
(cons 0 "MTEXT")
(CONS 8 "TITLE-BLOCK-TEXT")
(cons 410 (getvar "ctab"))
(cons -4  "<OR")
(cons 7  "helv-meds-19")
(cons 7  "helv14")
(cons -4  "OR>")
       )
       ))

I took the latter option. And it still did not work in the "helv14" TB.

That is because the style name is "HELV14" not "helv14"  :x :x  Computers just got to love them  :-)
Title: Re: Pulling information from a Field
Post by: Krushert on July 14, 2006, 04:32:43 PM
I have tested it on a bunch of drawings and it seems to work.
Thanks Guys for helping me out and letting me ahhh barrow <cough "steal"> your code.
I will plunk it to main routine come Monday and see how it plays out.  I will post it later.
I hope it was not too painful  :-)
Have a good weekend.
Thanks.
Title: Re: Pulling information from a Field
Post by: CAB on July 14, 2006, 05:28:12 PM
Glad you have some workable code to play with.

In my test, ACAD2000, the dxf 7 did not care if the case did not match.

This get nothing?
Code: [Select]
(setq ss (ssget "X" '((0 . "MTEXT")(7 . "helv14"))))
BTW you can also do you code this way, just FYI.

Code: [Select]
(setq ss1
       (ssget "_x"
      (list
'(0 . "MTEXT")
'(8 . "TITLE-BLOCK-TEXT")
(cons 410 (getvar "ctab"))
'(-4 . "<OR")
'(7  . "helv-meds-19")
'(7  . "helv14")
'(-4 . "OR>")
       )
       ))