Author Topic: Challenge (for the newbies)  (Read 9496 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Challenge (for the newbies)
« on: June 15, 2004, 10:28:55 AM »
Write a program that will set the layer and text style current of the selected text entity.

<pseudocode>
  prompt user to select an entity

  if entity = text
    collect layer and text style
 
   set current layer to text entity
   set current style to that of text entity
</pseudocode>
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Challenge (for the newbies)
« Reply #1 on: June 15, 2004, 01:56:38 PM »
...Im on it!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
Challenge (for the newbies)
« Reply #2 on: June 15, 2004, 02:11:16 PM »
lol
Se7en and CAB should be exposed to Dent's gasses  ..  newbies the man said, newbies!

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Challenge (for the newbies)
« Reply #3 on: June 15, 2004, 02:13:09 PM »
When can we submit our programs?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Challenge (for the newbies)
« Reply #4 on: June 15, 2004, 02:13:43 PM »
lol, well it was fun anyways
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Challenge (for the newbies)
« Reply #5 on: June 15, 2004, 02:17:03 PM »
Quote from: Se7en
When can we submit our programs?

Yes but for you it has to be all in ActiveX and completely bomb proof :D
TheSwamp.org  (serving the CAD community since 2003)

M-dub

  • Guest
Challenge (for the newbies)
« Reply #6 on: June 15, 2004, 02:18:02 PM »
Damn, I'd love to get into this, but I couldn't start it yet...We're starting a VB course on Friday in the office.  (One of the young gurus is going to teach us).  Good thing is that we're going to get paid for it and we're going to learn something, but still....I have a feeling that it's going to be pretty 'Mickey Mouse'.
It makes sense to me...how programs should work, but the language is what I've yet to learn.  I think I'll be good at it once I HAVE to learn it and devote some time to learning it.  Right now, I'm just too busy to dedicate time to it.  Anyway, I'm looking forward to getting there.  Maybe the VB will get me more into learning LISP too.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Challenge (for the newbies)
« Reply #7 on: June 15, 2004, 02:22:23 PM »
Quote from: Mark Thomas
Yes but for you it has to be all in ActiveX and completely bomb proof :D
WHAT?!  ...But i did it all with AutoLisp already?!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Challenge (for the newbies)
« Reply #8 on: June 15, 2004, 02:34:53 PM »
Oh by the way; because of "circumstances", I'm selling plain AutoLisp "crib notes" for this assignment.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Challenge (for the newbies)
« Reply #9 on: June 15, 2004, 02:35:20 PM »
Quote from: Se7en
Quote from: Mark Thomas
Yes but for you it has to be all in ActiveX and completely bomb proof :D
WHAT?!  ...But i did it all with AutoLisp already?!

well ok then......... go ahead and post it.
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Challenge (for the newbies)
« Reply #10 on: June 15, 2004, 02:47:31 PM »
Quote from: Mark Thomas
well ok then......... go ahead and post it.
HELOOOOoo?! ..Im selling it?!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Challenge (for the newbies)
« Reply #11 on: June 15, 2004, 02:57:34 PM »
Code: [Select]

(defun c:setstl(/ oldcmdecho en ent clr stl)
     (setq oldcmdecho (getvar "cmdecho"))
     (setvar "cmdecho" 0)
     (setq en (entsel "\nSelect Style/Layer By Entity:"))
     (if en
          (progn
               (setq ent (cdr (assoc 8 (entget (car en)))))
               (command "layer" "s" ent "")
               (setq stl (cdr (assoc 7 (entget (car en)))))
               (command "style" stl "" "" "" "" "" "" "")
          )
          (prompt "\n***Entity Not Selected...***")
     )
     (setvar "cmdecho" oldcmdecho)
     (princ)
)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Challenge (for the newbies)
« Reply #12 on: June 15, 2004, 03:23:56 PM »
Here was my version. Not alot of error checking but that can be added with little to no problems.
 
Code: [Select]
;;;*******************************************************************;
;;; Get and set layer and text style current of selected text ent.

;;; Safer entsel
(defun entse7 (/ x)
  (while (not (setq x (car (entsel))))
    (princ "\nYou missed, try again.")) x)
;;; Retrun the text style of an entity
(defun GetTxtStyle (ent) (cdr (assoc 7 (entget ent))))
;;; Return the layer of an entity
(defun GetLayer (ent) (cdr (assoc 8 (entget ent))))
;;; *** No need for the following cause the layer and
;;;     text style will already exist in the dwg ...dummy!?
;;; (defun Exist? (tpe ent) (and (tblsearch tpe ent)))
;;; ***
;;; Set the layer curent
(defun PutLayerCur (lay) (setvar "clayer" lay))
;;; set the text style current
(defun PutTxtStyleCur (sty) (setvar "textstyle" sty))
;;; Main
(defun c:PutStuffCur ( / ent)
  (setq ent (entse7))
  (PutTxtStyleCur (getTxtStyle ent))
  (PutLayerCur (getLayer ent))
 (princ)
)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Challenge (for the newbies)
« Reply #13 on: June 15, 2004, 03:29:32 PM »
Quote from: Mark Thomas
Quote from: Se7en
When can we submit our programs?

Yes but for you it has to be all in ActiveX and completely bomb proof :D

Just thought I'd give Se7en a hand since he's busy peddling his wares..... :twisted:
Code: [Select]

(defun c:set-lay-styl (/ doc ent)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if (and (setq ent (car (entsel "\nSelect Text object for style & layer to set current: ")))
  (setq ent (vlax-ename->vla-object ent))
  (vl-string-search "TEXT" (strcase (vla-get-objectname ent)))
  )
    (progn
      (vla-put-activelayer doc (vla-item (vla-get-layers doc) (vla-get-layer ent)))
      (vla-put-activetextstyle doc (vla-item (vla-get-textstyles doc) (vla-get-stylename ent)))
      )
    (princ "\nInvalid selection, exiting......")
    )
  (princ)
  )


Jeff
* darn, Se7en posted before I could get off the phone.......

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Challenge (for the newbies)
« Reply #14 on: June 15, 2004, 06:06:50 PM »
Nice one Jeff..
No time today, but had this one I use a lot.
Gimmee some of that gas anyway. :)
Code: [Select]
;;            SetCurrent.lsp        
;;      Created by C. Alan Butler  2003
;;
;;  Routine to set current Text or Dim Style by
;;  picking an existing object in the drawing  
;;  sets the layer of selected ent current as well
;;  
;;  Enter tds from the command line to run
;;  or set up a menu button with ^C^Ctds
;;;
;;;
;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;
;;;
(defun c:tds (/ ent entbl styold stynew usercmd)
  (if (setq ent
             (car (entsel "\nSelect Dimension or Text to make current: "))
      )
    (progn
      (setq entbl (entget ent)) ; Get entity definition list
      (setq usercmd (getvar "CMDECHO"))
      (setvar "CMDECHO" 0)
      (command "undo" "begin")
      (cond
        ((or (= "MTEXT" (cdr (assoc 0 entbl)))
             (= "TEXT" (cdr (assoc 0 entbl)))
         )
         (progn
           (setq stynew (cdr (assoc 7 entbl))
                 styold (getvar "textstyle")
           )
           (if (/= stynew nil)
             (setvar "TextStyle" stynew)
             (progn
               (setvar "TextStyle" "Standard")
               (setq stynew "STANDARD")
             )
           )
           (command "'Layer" "M" (cdr (assoc 8 entbl)) "")
           (prompt
             (strcat "\nText style changed from "
                     styold              " to "
                     stynew              "."
                    )
           )
         )
        ) ; end cond 1

        ((= "DIMENSION" (cdr (assoc 0 entbl)))
         (setq styold (getvar "dimstyle"))
         (command "dimstyle" "restore" "" ent)
         (setq stynew (getvar "dimstyle"))
         (command "'Layer" "M" (cdr (assoc 8 entbl)) "")
         (prompt
           (strcat "\nDimension style changed from "
                   styold                 " to "
                   stynew                 "."
                  )
         )
        ) ; end cond 2

        (t (prompt "\nSelection was not Text or Dimension.")
         ) ; end cond (T)
       
      ) ; end Cond stmt
      (command "undo" "end")
      (setvar "CMDECHO" usercmd)
      (princ)
    ) ; end progn
  ) ; endif
) ;End of Defun
(prompt "\nText / Dimension Style Changer Loaded, Type TDS to run")
(princ)
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.