Author Topic: ( Challenge ) Change Z value  (Read 8987 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
( Challenge ) Change Z value
« on: March 16, 2006, 08:53:08 AM »
Level: Beginner

Write a program that will change the Z value of selected (D)TEXT.

Example:
Select (D)TEXT to elevate:
Select point with desired elevation:
TheSwamp.org  (serving the CAD community since 2003)

nivuahc

  • Guest
Re: ( Challenge ) Change Z value
« Reply #1 on: March 16, 2006, 09:40:09 AM »
nice  :kewl:

should be a good'n

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Change Z value
« Reply #2 on: March 16, 2006, 10:19:00 AM »
Do you want to add to the value of the dtext? or just change it to that value?  Below will put the value of Z to what you enter.  If you want to add it, it won't be that hard either, change a couple of lines.

Code: [Select]
(defun c:ChangeTextZ (/ ss ValZ cnt Ent EntData Num InsPt)

(if
 (and
  (setq ValZ (getdist "\n Enter new Z value: "))
  (setq ss (ssget '((0 . "TEXT"))))
  (setq cnt -1)
 )
 (while (setq Ent (ssname ss (setq cnt (1+ cnt))))
  (setq EntData (entget Ent))
  (setq Num
   (if
    (and
     (equal (cdr (assoc 72 EntData)) 0)
     (equal (cdr (assoc 73 EntData)) 0)
    )
    10
    11
   )
  )
  (setq InsPt (cdr (assoc Num EntData)))
  (entmod
   (subst
    (cons Num (list (car InsPt) (cadr InsPt) ValZ))
    (assoc Num EntData)
    EntData
   )
  )
  (if (equal Num 11)
   (entmod
    (subst
     (cons
      10
      (list
       (car (cdr (assoc 10 EntData)))
       (cadr (cdr (assoc 10 EntData)))
       ValZ
      )
     )
     (assoc 10 EntData)
     EntData
    )
   )
  )
 )
)
(princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: ( Challenge ) Change Z value
« Reply #3 on: March 16, 2006, 10:21:16 AM »
Do you want to add to the value of the dtext? or just change it to that value?  Below will put the value of Z to what you enter.  If you want to add it, it won't be that hard either, change a couple of lines.

Quote
Level: Beginner

 :roll:

 :evil:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Change Z value
« Reply #4 on: March 16, 2006, 10:23:19 AM »
Do you want to add to the value of the dtext? or just change it to that value?  Below will put the value of Z to what you enter.  If you want to add it, it won't be that hard either, change a couple of lines.

Quote
Level: Beginner

 :roll:

 :evil:
I like giving options.  What can I say. :angel:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: ( Challenge ) Change Z value
« Reply #5 on: March 16, 2006, 10:51:25 AM »
Do you want to add to the value of the dtext? or just change it to that value?

Either will work and be just as fun.
TheSwamp.org  (serving the CAD community since 2003)

LE

  • Guest
Re: ( Challenge ) Change Z value
« Reply #6 on: March 16, 2006, 10:53:04 AM »
Beginner's solution:

Code: [Select]
(defun C:CHDTEXTE  (/ ss elev)
  (if (setq ss (ssget '((0 . "TEXT"))))
    (progn
      (if (not def)
(setq def 0.0))
      (setq elev (getdist (strcat "\nSpecify new elevation <" (rtos def) ">: ")))
      (if (not elev)
(setq elev def)
(setq def elev))
      (setvar "cmdecho" 0)
      (command "_.CHANGE" ss "" "_P" "_ELEV" elev "")
      (setvar "cmdecho" 1)))
  (princ))
(princ)

LE

  • Guest
Re: ( Challenge ) Change Z value
« Reply #7 on: March 16, 2006, 10:56:10 AM »
Or...

Code: [Select]
(defun C:CHTXTE (/ ss)
  (if (setq ss (ssget '((0 . "TEXT"))))
    (command "_.CHANGE" ss "" "_P" "_ELEV" pause ""))
  (princ))
(princ)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Change Z value
« Reply #8 on: March 16, 2006, 10:58:56 AM »
Good point Luis, but I like to teach beginners the code way. :oops:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: ( Challenge ) Change Z value
« Reply #9 on: March 16, 2006, 11:03:40 AM »
Good point Luis, but I like to teach beginners the code way. :oops:

I know... and it is good... I am just having fun going back some moons back....  :-)

Code: [Select]
(defun C:CHTXTE ()
  (vl-cmdf "_.CHANGE" (ssget '((0 . "TEXT"))) "" "_P" "_ELEV" pause "")
  (princ))

LE

  • Guest
Re: ( Challenge ) Change Z value
« Reply #10 on: March 16, 2006, 11:10:09 AM »
And by the way I still and always will, to consider my self a beginner...  :kewl:
« Last Edit: March 16, 2006, 11:33:23 AM by LE »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Change Z value
« Reply #11 on: March 16, 2006, 11:23:27 AM »
And by the way I still and always wil,l to consider my self a beginner...  :kewl:
Me too. :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: ( Challenge ) Change Z value
« Reply #12 on: March 16, 2006, 11:39:36 AM »
Methane alert.

:P
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Bob Wahr

  • Guest
Re: ( Challenge ) Change Z value
« Reply #13 on: March 16, 2006, 12:23:21 PM »
Because I reject lisp(and all other things in parenthesis(except for those things that need them))
Code: [Select]
Option Explicit
Public Sub PointZ()
  Dim varPoint As Variant
  Dim varPick As Variant
  Dim strKeyword As String
  Dim strHow As String
  Dim objDtext As AcadText
 
  On Error GoTo BrokeDown
 
  varPoint = ThisDrawing.Utility.GetPoint(, "Pick a point: ")
  ThisDrawing.Utility.GetEntity objDtext, varPick, "Pick some text: "
  strKeyword = "Append Overwrite"
  ThisDrawing.Utility.InitializeUserInput 0, strKeyword
  strHow = ThisDrawing.Utility.GetKeyword("Append or [Overwrite]: ")
  If strHow = "Append" Then
    objDtext.TextString = objDtext.TextString & " " & varPoint(2)
  Else
    objDtext.TextString = "El. = " & varPoint(2)
  End If
 
Bounce:
 Exit Sub
 
BrokeDown:
  Select Case Err.Number
    Case 13
      ThisDrawing.Utility.Prompt "That's not a piece of text" & vbCrLf
      Err.Clear
      Resume
    Case Else
      Debug.Print Err.Number
      Debug.Print Err.Description
      Error.clr
      MsgBox "Program fall down go boom!", vbCritical, "Ka-POW"
      GoTo Bounce
  End Select
End Sub

Bob Wahr

  • Guest
Re: ( Challenge ) Change Z value
« Reply #14 on: March 16, 2006, 12:25:01 PM »
Actually, by way of clarification, when you said "point" did you mean mouse click somewhere in space or did you want it done by selecting a point object?