Author Topic: ( Challenge ) Change Z value  (Read 8956 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?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Change Z value
« Reply #15 on: March 16, 2006, 12:34:30 PM »
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:
Oops.  Didn't see the example area completely when I posted my code.  If needs be I can change it, or you can figure out how to change it so it meets your needs.

Hint: Getpoint & caddr
Tim

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

Please think about donating if this post helped you.

Bob Wahr

  • Guest
Re: ( Challenge ) Change Z value
« Reply #16 on: March 16, 2006, 12:53:02 PM »
hmmm...looks like I missed that, and the intent, maybe some this
Code: [Select]
Option Explicit
Public Sub PointZAgain()
  Dim varPoint As Variant
  Dim varPick As Variant
  Dim objDtext As AcadText
  Dim dblEndPt(0 To 2) As Double
  On Error GoTo BrokeDown
 
  ThisDrawing.Utility.GetEntity objDtext, varPick, "Pick some text: "
  varPoint = ThisDrawing.Utility.GetPoint(, "Pick a point: ")
  dblEndPt(0) = objDtext.InsertionPoint(0)
  dblEndPt(1) = objDtext.InsertionPoint(1)
  dblEndPt(2) = varPoint(2)
  objDtext.Move objDtext.InsertionPoint, dblEndPt
 
 
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
      Err.Clear
      MsgBox "Program fall down go boom!", vbCritical, "Ka-POW"
      GoTo Bounce
  End Select
End Sub

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: ( Challenge ) Change Z value
« Reply #17 on: March 16, 2006, 01:51:48 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?
I meant by clicking on an object that has the desired Z value.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: ( Challenge ) Change Z value
« Reply #18 on: March 16, 2006, 02:02:05 PM »
How about something like these.

Code: [Select]
(defun c:elt ( / aztl ent pt elist)
  ;; change the Z value of the select (d)text entity.
  ;; Thu Mar 16, 2006

  (defun aztl (elist pt)
    ;; aztl = add Z value to list
    ;; elist = entity list
    ;; pt = point list, such as (100.00 200.00 10.0)
    ;;
    ;; returns a list with the Z value from 'pt'
    (list
      (car (cdr (assoc 10 elist)))
      (cadr (cdr (assoc 10 elist)))
      (last pt)
      )
    )

  (if (setq ent (car (entsel "\nSelect Text Item: ")))
    (if (setq pt (getpoint "\nSelect Point: "))
      (progn
        (setq elist (entget ent))

        (setq elist (subst (cons 10 (aztl elist pt))(assoc 10 elist) elist))

        (entmod elist)

        (princ (strcat "Changed to " (rtos (last (assoc 10 elist)))))

        )
      )
    )

  (princ)
  )

(defun c:clt ( / ss)

  (if
    (vl-cmdf "change"
             (setq ss (ssget '((0 . "TEXT"))))
             ""
             "P"
             "Elev"
             (last (getpoint "\nSelect Point: "))
             ""
             )
    (progn
      (princ (strcat (itoa (sslength ss)) " items changed"))
      (setq ss nil)
      )
    )
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

LE

  • Guest
Re: ( Challenge ) Change Z value
« Reply #19 on: March 16, 2006, 02:09:50 PM »
How about something like these.

Code: [Select]
             (last (getpoint "\nSelect Point: ")) ;;;<<<<<<<<
 

Nice, samples

I like that move you did using the last function... quite advanced for a beginner's coder but good.

 :-)

Have fun.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: ( Challenge ) Change Z value
« Reply #20 on: March 16, 2006, 02:14:13 PM »
How about something like these.

Code: [Select]
             (last (getpoint "\nSelect Point: ")) ;;;<<<<<<<<
 

Nice, samples

I like that move you did using the last function... quite advanced for a beginner's coder but good.
Thanks Luis, I'll take that as a compliment.  :-)
TheSwamp.org  (serving the CAD community since 2003)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Change Z value
« Reply #21 on: March 16, 2006, 02:23:31 PM »
Looks good to me.
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 #22 on: March 16, 2006, 02:50:21 PM »
testing ......... ignore please
TheSwamp.org  (serving the CAD community since 2003)