Jump to content

Recommended Posts

Posted

I have a block that has 3 attributes. One for Half, Full and double are the tag names. Im tryin to create a field link to a viewport custom scale which can take the field and place the value (either half or double) into the attributes.

 

I found this which works for the full scale value. I am wondering how to get the lisp to either add the half of the full value and double of the full value.

 

thank you for your help.

 

(defun c:scale (/ vpObj fldObj vpID util fldtxt)
  (vl-load-com)
  (setq	vpObj  (vlax-ename->vla-object
		 (car (nentsel "\nSelect the viewport: "))
	       )
	fldObj (vlax-ename->vla-object (car (nentsel "\nSelect the Full Attribute Block: ")))
	vpID   (vla-get-objectid vpObj)
  )
  (if (> (vl-string-search "x64" (getvar "platform")) 0)
    (progn
      (setq util (vla-get-Utility
		   (vla-get-activedocument (vlax-get-acad-object))
		 )
	    vpID (vlax-invoke-method
		   util
		   "GetObjectIdString"
		   vpObj
		   :vlax-False
		 )
      )
    )
    (setq vpID (vl-princ-to-string (vla-get-Objectid vpObj)))
  )
         (setq fldtxt (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                              vpID
                              ">%).CustomScale \\f \"%lu2%ct1%ps\%qf2816\">%"
                      )
  )
  (vla-put-textstring fldObj fldtxt)
  (vla-update fldObj)
  (vla-regen (vla-get-activedocument (vlax-get-acad-object))
	     1
  )
  (princ))

 

 

Posted

Use a formula field, e.g. for double:

"%<\\AcExpr (2*%<\\AcObjProp Object(%<\\_ObjId " vpID ">%).CustomScale>%) \\f \"%lu2\">%"

 

Posted

Thanks for the response back! I went deeper with the routine trying to utilize your LM:Setattributevalues. Either im close, or way the wrong direction.

 

Command: test
Select the viewport:
Select Block: Unknown command "0".  Press F1 for help.
; error: bad function: #<VLA-OBJECT IAcadAttributeReference 000001c3abeb6e88>

 

(defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun c:test (/ vpObj fldObj vpID util fldtxt fldtxthalf fldtxtDouble)
  (vl-load-com)
  (setq	vpObj  (vlax-ename->vla-object
		 (car (nentsel "\nSelect the viewport: "))
	       )
	fldObj (vlax-ename->vla-object (car (nentsel "\nSelect Block: ")))
	vpID   (vla-get-objectid vpObj)
  )
  (if (> (vl-string-search "x64" (getvar "platform")) 0)
    (progn
      (setq util (vla-get-Utility
		   (vla-get-activedocument (vlax-get-acad-object))
		 )
	    vpID (vlax-invoke-method
		   util
		   "GetObjectIdString"
		   vpObj
		   :vlax-False
		 )
      )
    )
    (setq vpID (vl-princ-to-string (vla-get-Objectid vpObj)))
  )

;;CustomScale Forumlas

      (setq fldtxthalf (strcat "%<\\AcExpr (0.5*%<\\AcObjProp Object(%<\\_ObjId " vpID ">%).CustomScale>%) \\f \"%lu2\">%"))

      (setq fldtxt (strcat "%<\\AcExpr (1*%<\\AcObjProp Object(%<\\_ObjId " vpID ">%).CustomScale>%) \\f \"%lu2\">%"))

      (setq fldtxtdouble (strcat "%<\\AcExpr (2*%<\\AcObjProp Object(%<\\_ObjId " vpID ">%).CustomScale>%) \\f \"%lu2\">%"))


;;Field Text to Attributes

    (progn 
           (setvar 'attreq 0)
           (command "insert" "test" p scl scl "0")
           (setq b (vlax-ename->vla-object (entlast)))
           ( lm:vl-setattributevalue b "half" (fldObj fldtxthalf))
           ( lm:vl-setattributevalue b "full" (strcat (fldObj fldtxt)))
           ( lm:vl-setattributevalue b "double" (strcat (fldObj fldtxtDouble) 2 2))
           (setvar 'attreq 1)
    )


;;  (vla-put-textstring fldObj fldtxt)
  (vla-update fldObj)
  (vla-regen (vla-get-activedocument (vlax-get-acad-object))
	     1
  )


  (princ))

 

BAR.dwg

Posted (edited)

@rcb007 

;; Change this
(lm:vl-setattributevalue b "half" (fldobj fldtxthalf))
(lm:vl-setattributevalue b "full" (strcat (fldobj fldtxt)))
(lm:vl-setattributevalue b "double" (strcat (fldobj fldtxtdouble) 2 2))
;; To this
(progn ;; (setvar 'attreq 0)
	 ;;(command "insert" "test" scl scl "0")
	 ;;(setq b (vlax-ename->vla-object (entlast)))
	 (lm:vl-setattributevalue fldobj "half" fldtxthalf)
	 (lm:vl-setattributevalue fldobj "full" fldtxt)
	 (lm:vl-setattributevalue fldobj "double" fldtxtdouble)
	 ;; (setvar 'attreq 1)
  )

Depending on your version of CAD you can use setpropertyvalue as well.

(setpropertyvalue (entlast) "half" fldtxthalf)

And you don't have your insertion point 'p' or scale 'scl' defined for a block .. although you select a block at the top?

(command "insert" "test" p scl scl "0")

There are many more errors and I'm done chasing them...

Edited by ronjonp
Posted

Wow. Thank you. Would the LM-Setattributevaule still be able to work through a dynamic block? I know the block I showed was a normal block. I wanted to know what would need to be changed if any, for it to work.

Posted (edited)

See if this sheds any light:

(defun c:test (/ fldobj util vpid vpobj)
  (if (and (setq vpobj (car (entsel "\nPick viewport: ")))
	   ;; Add a check that it's a viewport selected
	   (setq fldobj (car (entsel "\nSelect Block: ")))
	   ;; Add a check that it's your barscale selected
	   (setq vpid (vla-get-objectid (setq vpobj (vlax-ename->vla-object vpobj))))
      )
    (progn
      (if (> (vl-string-search "x64" (getvar "platform")) 0)
	(progn (setq util (vla-get-utility (vla-get-activedocument (vlax-get-acad-object)))
		     vpid (vlax-invoke-method util "GetObjectIdString" vpobj :vlax-false)
	       )
	)
	(setq vpid (vl-princ-to-string (vla-get-objectid vpobj)))
      )
      (foreach a '("half" "full" "double")
	(setpropertyvalue
	  fldobj
	  a
	  (strcat "%<\\AcExpr ("
		  (cond	((= a "half") "0.5")
			((= a "full") "1.")
			((= a "double") "2.")
		  )
		  "*%<\\AcObjProp Object(%<\\_ObjId "
		  vpid
		  ">%).CustomScale>%) \\f \"%lu2\">%"
	  )
	)
      )
      (vla-regen (vla-get-activedocument (vlax-get-acad-object)) 1)
    )
  )
  (princ)
)
(vl-load-com)

 

Edited by ronjonp
  • Like 1
Posted

Thank you again ronjonp. I do see it. Way a lot cleaner and to use the setpropertyvalue variable.

Posted
3 minutes ago, rcb007 said:

Thank you again ronjonp. I do see it. Way a lot cleaner and to use the setpropertyvalue variable.

🍻

Posted

I am not sure if I am missing something or not, this routine works awesome with an mview and selected block. I just tried to use it with a irregular rectangle. I am not sure how to change the field so that it would select either or. I thought a mview was a mview even if it was a polyline type viewport.

thanks

Posted

Use something like this:

(defun _getviewport (e)
  (if e
    (cond ((= "VIEWPORT" (cdr (assoc 0 (entget e)))) e)
	  ((cdadr (member '(102 . "{ACAD_REACTORS") (entget e))))
    )
  )
)
;; (_getviewport (car (entsel "\nPick a viewport: ")))

 

Posted

Got it! Adjust the code and it works. Thank you once again!

Posted
4 minutes ago, rcb007 said:

Got it! Adjust the code and it works. Thank you once again!

🍻

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