Jump to content

retreiving text or random attribute


flowerrobot

Recommended Posts

Howdy

 

Basicly, i have gotten sick of a old lisp we use.

I have edited it so that it will do any single or multi text.

but i would like to be able to select numbers in a block, or number appearing randomly in attributes, as i only know its possible if you know the attrubtes name, while i only want one's i select.

so any help from you smart people would be great

 

cheers flower

 

 

 

 

 

 

 

; tot allows user to select numbers on a drawing and it will add them all up and give you a total.
; The numbers must be in text format (not attributes or blocked) and can be selected with a window
; This is useful for summing up masses of components listed in a parts list.
;
; by FPr  Sept-1996
;edited by flower 15 jan
;;;*===========================================================
(defun initerr ()
(graphscr)
 (setq oldlayer (getvar "clayer"))
 (setq oldsnap (getvar "osmode"))
 (setq oldpick (getvar "pickbox"))
 (setq temperr *error*)
 (setq *error* trap)
 (command "dimsah" "off")
 (command "dimse2" "off")
 (command "dimblk2" "")
 (princ)
)                    ;defun
;;;*===========================================================
(defun trap (errmsg)
 (command nil nil nil)
 (if (not (member errmsg '("console break" "Function Cancelled"))
     )
   (princ (strcat "\nError: " errmsg))
 )                    ;                 
 (setvar "clayer" oldlayer)
 (setvar "blipmode" 0)
 (setvar "menuecho" 0)
 (setvar "highlight" 1)
 (setvar "osmode" oldsnap)
 (setvar "pickbox" oldpick)
 (command "dimsah" "off")
 (command "dimse2" "off")
 (command "dimblk2" "")
 (princ "\nError Resetting Enviroment ")
 (terpri)
 (setq *error* temperr)
 (princ)
)                    ;defun
;;;*===========================================================
(defun reset ()
 (setq *error* temperr)
 (setvar "clayer" oldlayer)
 (setvar "blipmode" 0)
 (setvar "menuecho" 0)
 (setvar "highlight" 1)
 (setvar "osmode" oldsnap)
 (setvar "pickbox" oldpick)
 (princ)
)    
(defun c:tot (/ CT IN NM ST SM)
(initerr)
 (setq ST (ssget))
 (setq CT 0)
 (setq SM 0)
 (while (< CT (sslength ST))
   (setq NM(ssname ST CT))
   (COND (OR (= "TEXT") (=  "MTEXT")) (cdr (assoc 0(entget NM)))
     (princ)
     (progn
       (ssdel NM ST)
       (setq CT(1- CT))
     )
   )
   (setq CT(1+ CT))
 )
 (setq CT 0)
 (if (= nil ST)
   (princ)
   (while (< CT (sslength ST))
     (setq NM(ssname ST CT))
     (setq IN (atoi (cdr (assoc 1 (entget NM)))))
     (princ IN)
     (setq SM (+ IN SM))
     (princ "\n")(princ)
     (setq CT(1+ CT))
   )
 )
 (princ (strcat "Total = " (rtos SM)))
 (princ)
)

               ;defun
;;;*===========================================================

Link to comment
Share on other sites

How I understand it:

 

  • You want to be able to select a block, or multiple blocks, and retrieve the total of some numbers within the block attributes.

Some questions:

 

  • Are the attributes solely numbers, (or is there other text in the same attribute?)
  • Do the blocks only have one attribute?
  • Do you know the name of the attribute involved - and will it always be the same one?
  • What output would you like (i.e., text insert, print to command line, alert box?)

Thanks

 

Lee

Link to comment
Share on other sites

Sorry im suffering from lack of sleep, newborn + loud neigbours = zombie

 

How I understand it:
  • You want to be able to select a block, or multiple blocks, and retrieve the total of some numbers within the block attributes.

Correct, text in blocks, or attributes, or just normal text as is

Some questions:

  • Are the attributes solely numbers, (or is there other text in the same attribute?)

Yes, i only want it to select number only text

  • Do the blocks only have one attribute?

No, hence the probblem, the name of the attribute will change,i would just like to be able to seclect the number, in the attribute, and it will be read at face value.

 

if you use the current one /\, place an attributed block with numbers, mtext and text , all with numbers.

the "burst" the attributed block, and run the command, this is what i want to accur

  • Do you know the name of the attribute involved - and will it always be the same one?

  • What output would you like (i.e., text insert, print to command line, alert box?)

Yes, i will have two options, placing the number in a block call "A1" with attribute called "Weld_mass"

 

or insert a block and place in that attribute, or maybe edit the block if it exsits, not sure yet

 

Thanks

No thank you

 

Lee

Link to comment
Share on other sites

Not sure if this helps

 

1 You can pick an object thats either text or a block in the case of the block read the attributes else its text.

 

2 Now you have a answer write it to another block.

 

3 No problems I do this now.

 

Ok I now use VBA for block manipulation the nice thing is the attributes are numbered not labled ie attrib(0) attrib(1) atrrib(2) etc a block is unique the attribute is always the same number unless you recreate.

 

So I pick text or block and read an answer then I find the block I want to change and write that answer into it.

 

Newpitname = "1"   'dummy to pass then return changed
pitname = Getpitname(Newpitname)
'Call Getpitname(pitname)
MsgBox "pitname selected is " & pitname

Function Getpitname(Newpitname As String) As String
Dim PitNameSelect As AcadObject
Dim pitattribs As Variant

ThisDrawing.Utility.GetEntity PitNameSelect, basepnt, "pick pit name : "
If PitNameSelect.ObjectName = "AcDbText" Then
 Getpitname = PitNameSelect.TextString
End If
If PitNameSelect.ObjectName = "AcDbBlockReference" Then
 pitblname = PitNameSelect.Name   ' RETURNS BLOCK NAME
 pitattribs = PitNameSelect.GetAttributes
 Getpitname = pitattribs(0).TextString
End If

End Function

 

Now pick a block get its attributes or insert a new one and update the attributes (this was here in the forum just before christmas)

 

attribs(7).TextString = pitsurfRL
attribs(.TextString = pitILin

attribs(.Update
attribs(7).Update

 

I am still confused as to what exactly you are trying to do but hope I have pointed out how it can be done.

Link to comment
Share on other sites

Bro, thanks for the help, but i saddly have no understanding of vba.

So i carnt even manipulate it

 

hopefull this will help a little.

 

i want it to have an answer of 17,.....3 + 1 + 8 + 5.

the phantom line, is my selection menu.

eg.jpg

Link to comment
Share on other sites

Yeah not a problem to do just pick all objects check what they are and add their values as numbers together. Be carefull with the blocks.

 

Following on from Lee Mac if you pick a piece of text with numbers in it will be bigger job to find the numbers, (look at my last post about layers code almost there) as a default just convert to a number answer is false if its any type of text therefore not used.

 

There is heaps of lisp examples here that ask for selections and pulls that object apart finding the values ie need block mtext text subroutines. May take a bit of searching try "selection set" more than likely there is one that does it all.

Link to comment
Share on other sites

So the Text with number (dodgy text as it is...) can be ignored I take it.

 

You mean the one that says, "i can see 4"

yes, that is to be ignored. leaving the 3 , 1 , 8 , 5, to only be read.

 

 

Bigal, So your saying your code you posted up will do this??

(sorry its being a lonng week)

 

cheers guys

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...