Author Topic: New lisp comments are welcomed  (Read 2076 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
New lisp comments are welcomed
« on: April 02, 2013, 01:45:49 AM »
Code: [Select]
;|----------- Modify Z level  ------------------

  Modify attribute to read level z and
  modify it automaticaly
 
  Modify block angle to 0
 
------------------------------------------------
  Author: Hasan M. Asous, 2013
ALL RIGHT RESERVED TO ALL
  Contact: HasanCAD @ TheSwamp.org,
           asos2000 @ CADTutor.net
           HasanCAD@gmail.com
------------------------------------------------
  Version: 1      2013 04 01
________________________________________________
      |;


;       Subroutine Start       ;

(defun get-objectid-x86-x64  (obj / util) ; fixo @ thesawmp.org
    (setq util (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))))
    (if (= (type obj) 'ename) (setq obj (vlax-ename->vla-object obj))) ;_ end of if
    (if (= (type obj) 'vla-object)      (if (> (vl-string-search "x64" (getvar "platform")) 0) (vlax-invoke-method util "GetObjectIdString" obj :vlax-false)
(rtos (vla-get-objectid obj) 2 0))))

(defun LM:vl-SetAttributeValue (block tag value) ; Lee Mac, Copyright © 2010 - www.lee-mac.com
    (setq tag (strcase tag))
    (vl-some (function
       (lambda (attrib)
(if (eq tag (strcase (vla-get-TagString attrib))) (progn (vla-put-TextString attrib value) value))))
     (vlax-invoke block 'GetAttributes)))

;        Subroutine End        ;


;       Mainroutine Start      ;

(defun c:zhght ( / ACSP ADOC BLK CNT FIELDSTR FOO OBJID SSBLK) (vl-load-com)

  (setq blknm "SRVPNO2") ; Block name
  (setq atttg "ELEV2")   ; attribute Tag
  (setvar "fielddisplay" 0)

  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq acsp (vla-get-block (vla-get-activelayout adoc)))
  (setq cnt 0)
 
  (if (setq ssblk (ssget "_X" (list (cons 0 "INSERT") (cons 2 "SRVPNO2") (cons 66 1) )))
    (progn
      (while (sslength ssblk)
(setq blk (vlax-ename->vla-object (ssname ssblk cnt)))
(setq objId (get-objectid-x86-x64 blk))
(setq fieldStr (strcat "%<\\AcObjProp Object(%<\\_ObjId " objId ">%).InsertionPoint \\f \"%lu2%pt4%pr3\">%"))
(setq foo (LM:vl-SetAttributeValue blk atttg fieldStr))
(vla-put-rotation blk 0)
(setq cnt (1+ cnt))
))))
(princ)

;       Mainroutine End        ;

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: New lisp comments are welcomed
« Reply #1 on: April 02, 2013, 02:08:59 AM »
Is there a way to change attributes textstyle?

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: New lisp comments are welcomed
« Reply #2 on: April 02, 2013, 02:24:14 AM »
Hi Hasan

Use (vla-put-StyleName AttributeObject "TextStyle").
Note: "TextStyle" must exist.

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Coder

  • Swamp Rat
  • Posts: 827
Re: New lisp comments are welcomed
« Reply #3 on: April 02, 2013, 04:40:38 AM »
What's the use of the following functions in your codes ?.

Code: [Select]
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq acsp (vla-get-block (vla-get-activelayout adoc)))

You assigned string to a variable and did not use it .

Code: [Select]
(setq blknm "SRVPNO2") ; Block name

How this would end ?

Code: [Select]
(while (sslength ssblk)

You are changing the system variable without returning it back as it was .

Code: [Select]
  (setvar "fielddisplay" 0)


This is what I have noticed in a quick look . :)

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: New lisp comments are welcomed
« Reply #4 on: April 02, 2013, 05:17:15 AM »
Code: [Select]
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq acsp (vla-get-block (vla-get-activelayout adoc)))
Deleted

You assigned string to a variable and did not use it .
Code: [Select]
(setq blknm "SRVPNO2") ; Block name
OK

How this would end ?
Code: [Select]
(while (sslength ssblk)
its the selected blocks quantity
You are changing the system variable without returning it back as it was .
Code: [Select]
  (setvar "fielddisplay" 0)
It is needed like that to change system variable

This is what I have noticed in a quick look . :)
Thanks for your quick look

Coder

  • Swamp Rat
  • Posts: 827
Re: New lisp comments are welcomed
« Reply #5 on: April 02, 2013, 06:36:27 AM »
How this would end ?
Code: [Select]
(while (sslength ssblk)
its the selected blocks quantity

Correct , but it would not end as long as the quantity would not be equal to nil  :wink:

You are changing the system variable without returning it back as it was .
Code: [Select]
  (setvar "fielddisplay" 0)
It is needed like that to change system variable

If you are writing that code for yourself , I agree otherwise you should add error trap to reset the user settings .

:)

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: New lisp comments are welcomed
« Reply #6 on: April 02, 2013, 08:27:00 AM »
Correct , but it would not end as long as the quantity would not be equal to nil  :wink:
Correct , but it would not end as long as the quantity would not be equal to nil  :wink:

Is this solution good
Code: [Select]
(if (< 0 (sslength (setq ssblk (ssget "_X" (list (cons 0 "INSERT") (cons 2 blknm) (cons 66 1) )))))
    (progn
      ))

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: New lisp comments are welcomed
« Reply #7 on: April 02, 2013, 08:39:52 AM »
Hi Hasan

Code: [Select]
(if (setq ssblk (ssget "_X" (list (cons 0 "INSERT") (cons 2 "SRVPNO2") (cons 66 1))))
 (while (setq Ent (ssname ssblk 0))
  (setq blk (vlax-ename->vla-object Ent))
  ...
  (ssdel Ent ssblk)
 )
)
does the stuff...

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18