Jump to content

SYNC ATTRIBUTE FIELD


Recommended Posts

Hi everyone 

i need yours help again

 

i'm trying copy field from one block to another block

the problem is that in the end i cant see the resault and it show me ####

only if i go inside the field and press ok it show me the resault

 

any idea how to fix it

 

 

Capture.PNG

MOLS.lsp

Link to post
Share on other sites
1 hour ago, Tharwat said:

Call the command REGEN after copying if your codes running correctly without any issue.

 

i try it already

its not refresh it

maybe because its field inside field

Link to post
Share on other sites

The main issue is that you are selecting the block reference with (car (entsel)). A block reference does not have a TextString property.

(defun C:MOLS (/ att base blk doc obj sca space str)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq space
    (if (= 1 (getvar 'cvport))
      (vla-get-paperspace doc)
      (vla-get-modelspace doc)
    )
  )
  (setq obj (car (nentsel "\nSelect an attribute: ")))
  (setq base (getpoint "\nSelect base point: "))
  (setq str (strcat "%<\\AcObjProp.16.2 Object(%<\\_ObjId " (itoa(vla-get-ObjectID (vlax-ename->vla-object obj))) ">%).TextString \\f \"%tc1\">%"))
  (setq sca (getvar 'dimscale))
  (setq blk
    (vla-insertblock
      space
      (vlax-3d-point base)
      "SH1"
      sca
      sca
      sca
      0
    )
  )
  (setq att (car (vlax-invoke blk 'getattributes)))
  (vla-put-textstring att str)
  (princ)
)

 

Link to post
Share on other sites

ROY THX

ITS WORK :)

THE ISSUE IS THAT WORKING ONLY IF I DIRECTLY POINT ON THE ATTRIBUTE TEXT AND NOT THE BLOCK

THERE IS ANYWAY TO CHANGE IT?

OR ATLEAST IT WONT LET ME CHOOSE THE BLOCK 

Link to post
Share on other sites
(defun C:MOLS (/ attNew attSel base doc enmSel objNew objSel sca space str)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-endundomark doc)
  (vla-startundomark doc)
  (if
    (and
      (setq enmSel (car (entsel)))
      (setq objSel (vlax-ename->vla-object enmSel))
      (vlax-method-applicable-p objSel 'getattributes)
      (setq attSel (car (vlax-invoke objSel 'getattributes)))
      (setq base (getpoint "\nSelect Base Point: "))
    )
    (progn
      (setq space
        (if (= 1 (getvar 'cvport))
          (vla-get-paperspace doc)
          (vla-get-modelspace doc)
        )
      )
      (setq str
        (strcat
          "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
          (itoa (vla-get-objectid attSel))
          ">%).TextString \\f \"%tc1\">%"
        )
      )
      (setq sca (getvar 'dimscale))
      (setq objNew
        (vla-insertblock
          space
          (vlax-3d-point base)
          "SH1"
          sca
          sca
          sca
          0
        )
      )
      (setq attNew (car (vlax-invoke objNew 'getattributes)))
      (vla-put-textstring attNew str)
    )
  )
  (vla-endundomark doc)
  (princ)
)

 

Link to post
Share on other sites
16 hours ago, Roy_043 said:

(defun C:MOLS (/ attNew attSel base doc enmSel objNew objSel sca space str)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-endundomark doc)
  (vla-startundomark doc)
  (if
    (and
      (setq enmSel (car (entsel)))
      (setq objSel (vlax-ename->vla-object enmSel))
      (vlax-method-applicable-p objSel 'getattributes)
      (setq attSel (car (vlax-invoke objSel 'getattributes)))
      (setq base (getpoint "\nSelect Base Point: "))
    )
    (progn
      (setq space
        (if (= 1 (getvar 'cvport))
          (vla-get-paperspace doc)
          (vla-get-modelspace doc)
        )
      )
      (setq str
        (strcat
          "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
          (itoa (vla-get-objectid attSel))
          ">%).TextString \\f \"%tc1\">%"
        )
      )
      (setq sca (getvar 'dimscale))
      (setq objNew
        (vla-insertblock
          space
          (vlax-3d-point base)
          "SH1"
          sca
          sca
          sca
          0
        )
      )
      (setq attNew (car (vlax-invoke objNew 'getattributes)))
      (vla-put-textstring attNew str)
    )
  )
  (vla-endundomark doc)
  (princ)
)

HI ROY

THIS ONE NOT WORKING

HE CANT FIND THE FIELD

 

Link to post
Share on other sites

First of all: please switch off CapsLock when writing forum posts. All caps texts are annoying.

 

Are you testing the new code on the same machine and AutoCAD version as the previous code?

Link to post
Share on other sites
2 hours ago, Roy_043 said:

First of all: please switch off CapsLock when writing forum posts. All caps texts are annoying.

 

Are you testing the new code on the same machine and AutoCAD version as the previous code?

Sorry for the CapsLock

 

i change the Code because it didnt work and use the nentsel that u advise

there is the code that i use

(defun C:MOLS (/ obj )

		(vl-load-com)
		(setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
		(setq Space
			(if (= 1 (getvar "CVPORT"))
				(vla-get-PaperSpace AcDoc)
				(vla-get-ModelSpace AcDoc)
			)
		)

	;(setq obj (car (entsel "\nSelect an Attributed Block: ")))
	(setq obj (car (nentsel "\nSelect an attribute: ")))

	(setq BASE (getpoint "\nSelect Base Point: "))
	
	(setq YY 	(strcat "%<\\AcObjProp.16.2 Object(%<\\_ObjId " (itoa(vla-get-ObjectID (vlax-ename->vla-object obj))) ">%).TextString \\f \"%tc1\">%"))
	(command "_.Insert" "SH1" base (getvar "DIMSCALE") "" "" YY "")


(prin1)
) ;END

 

Link to post
Share on other sites

Just saying 'it does not work' is not going to get us anywhere. I have made an assumption regarding the source block that is selected. That assumption may be wrong. Please post a file with a block that the new code does not handle properly.

Link to post
Share on other sites
29 minutes ago, Roy_043 said:

Just saying 'it does not work' is not going to get us anywhere. I have made an assumption regarding the source block that is selected. That assumption may be wrong. Please post a file with a block that the new code does not handle properly.

Hi roy

I add the DWG with the block

next to each block i write text

the main goal is to read the middle block (that contain data from the below block) and make a new block (the top one)

 

thx again for the help

new block.dwg

Link to post
Share on other sites

The new code seems to work OK with your example DWG. The source block you select has a single attribute, and this matches my assumption. I can't think of a reason why the first version of my code works and the second version fails, other than that you are testing with different AutoCAD versions (32/64 bit).

Link to post
Share on other sites

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
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...