Author Topic: Spaces in names  (Read 3847 times)

0 Members and 1 Guest are viewing this topic.

CADaver

  • Guest
Spaces in names
« on: April 17, 2006, 02:41:26 PM »
Okay, this ought to be easy, but I'm missing it somewhere.  I have a little routine for finding an xref layer name and changing the color of that layer.  Unfortunately it blows up if the file or layer name has a space in it.  It reads the space as an ENTER, in the layer command and boggles it up.  How do I test for and control spaces in table names?

Code: [Select]
(defun c:xrc ()
(command ".undo" "begin")
  (setq clrnum (acad_colordlg 10))
    (pplist)
    (command ".layer" "c" clrnum slayer "")
(command ".undo" "end")
(princ)
)

(defun pplist ()
(setq xrpick (nentsel "\nSelect nested xref: "))
(setq xrnested (length (last xrpick)))
  (if (= xrnested 1)
    (setq xrlist (entget (car xrpick))) ;then pull the list from the standard nentsel call.
    (setq xrlist (entget (nth (- xrnested 2) (last xrpick))))  ;else last last our way back up to the top block definition
  );end if
  (setq sLayer (cdr (assoc 8 xrlist))
        xrobjectTYPE (cdr (assoc 0 xrlist))
        xrobjectNAME (cdr (assoc 2 xrlist))
        ppnm ""
  ); end setq
(princ)
)


LE

  • Guest
Re: Spaces in names
« Reply #1 on: April 17, 2006, 02:47:50 PM »
I think you need to have a look into snvalid, Randy.

btw, that will lead you to EXTNAMES... too
« Last Edit: April 17, 2006, 02:51:43 PM by LE »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Spaces in names
« Reply #2 on: April 17, 2006, 02:51:42 PM »
Perhaps --

Code: [Select]
(defun QuoteItIfNecessary ( text )
    (if (vl-string-position 32 text)
        (strcat "\"" text "\"")
        text
    )
)

Then --

Code: [Select]
(defun c:xrc ()
    (command ".undo" "begin")
    (setq clrnum (acad_colordlg 10))
    (pplist)
    (command ".layer" "c" clrnum (QuoteItIfNecessary slayer) "")
    (command ".undo" "end")
    (princ)
)

<< untested >>

Note -- look at extnames system variable.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CADaver

  • Guest
Re: Spaces in names
« Reply #3 on: April 17, 2006, 03:24:18 PM »
Thanks Michael, that works.  Moved the "QuoteIfNecessary" function to the PPLIST routine so it's available for all uses of pplist.  I'm quite sure someone here has a much more elegant solution for changing the color of individual xref layers (hint; hint; trolling for code; nudge; nudge; wink; wink; say no more)  :angel:  (Actually, I use pplist as an engine for several routines for listing and labeling xref nested elements.)

Code: [Select]
(defun c:xrc ()
(command ".undo" "begin")
  (setq clrnum (acad_colordlg 10))
    (pplist)
    (command ".layer" "c" clrnum slayer "")
(command ".undo" "end")
(princ)
)

(defun pplist ()
(setq xrpick (nentsel "\nSelect nested xref: "))
(setq xrnested (length (last xrpick)))
  (if (= xrnested 1)
    (setq xrlist (entget (car xrpick))) ;then pull the list from the standard nentsel call.
    (setq xrlist (entget (nth (- xrnested 2) (last xrpick))))  ;else last last our way back up to the top block definition
  );end if
  (setq sLayer (QuoteItIfNecessary (cdr (assoc 8 xrlist))) ;;;;;;;;;;;;<- added QuoteIfNecessary here
        xrobjectTYPE (cdr (assoc 0 xrlist))
        xrobjectNAME (cdr (assoc 2 xrlist))
        ppnm ""
  ); end setq
(princ)
)

CADaver

  • Guest
Re: Spaces in names
« Reply #4 on: April 17, 2006, 03:55:26 PM »
Okay, Michael, that works if the layer name has spaces, but fails if the XREF file name has spaces;

Works for layer:
"F101_C104_C105_1_EXIST|FDN F-101 C-106"
Doesn't work for layer:
"241-242_MASTER FDN PLAN|COMPRESSOR_SHED_FDN"

My current solution is banning all special characters except dashes and underbars  :pissed: 


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Spaces in names
« Reply #5 on: April 17, 2006, 04:00:28 PM »
Randy
Maybe I missed something but I am struggling with the pplist routine.
I changed it to this, trapping non complex objects but still not sure which layer you are after.

Code: [Select]
(defun pplist ()
  (setq xrpick (nentsel "\nSelect nested xref: "))
  (if (> (length xrpick) 2)
    (if (= (length (last xrpick)) 1)
      (setq xrlist (entget (car xrpick))) ; nested one deep
      (setq xrlist ???????????????
    )
    (progn
      (alert "Not a complex object")
      (exit)
    )
  ) ;end if
  (setq slayer       (cdr (assoc 8 xrlist))
        xrobjecttype (cdr (assoc 0 xrlist))
        xrobjectname (cdr (assoc 2 xrlist))
        ppnm         ""
  ) ; end setq
  (princ)
)

This is what I was working with:
if nentsel returns this:
Code: [Select]
(<Entity name: 1b6ccd0>   ;;  <--<<  entity selected
  (117.535 626.004 0.0)
  ( (0.965926 0.258819 0.0)
    (-0.258819 0.965926 0.0)
    (0.0 0.0 1.0)
    (-3153.9 594.558 0.0)
  )
  ( <Entity name: 1b6bcf8> ;; <--<<  block the entity is in  <--<< this layer ??
    <Entity name: 1b6cc90> ;; <--<<  block the block is in
  )
)

You are looking for the layer the inner block is on?
If so
(setq xrlist (car (last xrpick)))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Spaces in names
« Reply #6 on: April 17, 2006, 04:27:55 PM »
Well I tried it with file "241-242_MASTER FDN PLAN" and layer "COMPRESSOR_SHED_FDN"
Result is layer "241-242_MASTER FDN PLAN|COMPRESSOR_SHED_FDN"
Worked on ACAD2000 and 2004 with extnames set to 1 or 0
No problems. :?

PS this is without the QuoteItIfNecessary routine.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CADaver

  • Guest
Re: Spaces in names
« Reply #7 on: April 18, 2006, 11:25:28 AM »
Well I tried it with file "241-242_MASTER FDN PLAN" and layer "COMPRESSOR_SHED_FDN"
Result is layer "241-242_MASTER FDN PLAN|COMPRESSOR_SHED_FDN"
Worked on ACAD2000 and 2004 with extnames set to 1 or 0
No problems. :?

PS this is without the QuoteItIfNecessary routine.
Yes, that is what nentsel returns.  However when I re-use that layer name in the layer command in XRC.lsp the first space in the name is read as an enter and blows up. Hence the QuoteItIfNecessary routine.  If you have another way around it, Please let me know.


BTW,
Code: [Select]
  (if (= (length (last xrpick)) 1)
     (setq xrlist (entget (car xrpick))) ; nested one deep
     (setq xrlist ???????????????
  )
Code: [Select]
  (if (= (length (last xrpick)) 1)
      (setq xrlist (entget (car xrpick))) ;then pull the list from the standard nentsel call.
      (setq xrlist (entget (nth (- xrnested 2) (last xrpick))))  ;else last last our way back up to the top block definition
  );end if
the second xrlist is for nested xrefs.  I wanted to step back up to the top nested level, otherwise when selecting blocks created on layer 0 that are in an xref, I'd only change the color of layer 0. That's the first way I found around it.

Oh, I like the trapping non complex objects part and losing the xrnested variable.  Thanks.


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Spaces in names
« Reply #8 on: April 18, 2006, 11:45:02 AM »
Yes, that is what nentsel returns.  However when I re-use that layer name in the layer command in XRC.lsp the first space in the name is read as an enter and blows up. Hence the QuoteItIfNecessary routine.  If you have another way around it, Please let me know.
I used the complete routine & the layer command had no problem with that layer name.

Quote
the second xrlist is for nested xrefs.  I wanted to step back up to the top nested level, otherwise when selecting blocks created on layer 0 that are in an xref, I'd only change the color of layer 0. That's the first way I found around it.
I though that is what this returns?
(setq xrlist (car (last xrpick)))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CADaver

  • Guest
Re: Spaces in names
« Reply #9 on: April 18, 2006, 02:53:46 PM »
AAAAACK!!!! BLIND BLIND BLIND    :x :oops: :cry: :ugly: :-P

Code: [Select]
(defun c:xrc ()
    (command ".undo" "begin")
    (setq clrnum (acad_colordlg 10))
       (pplist)
    (command ".layer" "c" clrnum slayer "")
    (command ".undo" "end")
 (princ)
)


(defun pplist ()
  (setq xrpick (nentsel "\nSelect nested xref: "))
  (if (> (length xrpick) 2)
    (progn
        (setq xrlist (entget (car (last xrpick))))
        (setq sLayer (cdr (assoc 8 xrlist))
                 xrobjectTYPE (cdr (assoc 0 xrlist))
                 xrobjectNAME (cdr (assoc 2 xrlist))
                 ppnm ""
        ); end setq
    )
    (progn
      (alert "Not a complex object")
      (exit)
    )
  ) ;end if
  (princ)
)
Works just like I want.   I was making it a LOT harder than it needed to be.

Still dunno why the spaces blow up going my originally lame way, but they do here.

Thanks a load guys, now to localize variables trap errors and clean it up. 
I appreciate the help.