TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mark 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:
-
nice :kewl:
should be a good'n
-
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.
(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)
)
-
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.
Level: Beginner
:roll:
:evil:
-
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.
Level: Beginner
:roll:
:evil:
I like giving options. What can I say. :angel:
-
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.
-
Beginner's solution:
(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)
-
Or...
(defun C:CHTXTE (/ ss)
(if (setq ss (ssget '((0 . "TEXT"))))
(command "_.CHANGE" ss "" "_P" "_ELEV" pause ""))
(princ))
(princ)
-
Good point Luis, but I like to teach beginners the code way. :oops:
-
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.... :-)
(defun C:CHTXTE ()
(vl-cmdf "_.CHANGE" (ssget '((0 . "TEXT"))) "" "_P" "_ELEV" pause "")
(princ))
-
And by the way I still and always will, to consider my self a beginner... :kewl:
-
And by the way I still and always wil,l to consider my self a beginner... :kewl:
Me too. :-)
-
Methane alert.
:P
-
Because I reject lisp(and all other things in parenthesis(except for those things that need them))
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
-
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?
-
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
-
hmmm...looks like I missed that, and the intent, maybe some this
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
-
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.
-
How about something like these.
(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)
)
-
How about something like these.
(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.
-
How about something like these.
(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. :-)
-
Looks good to me.
-
testing ......... ignore please