Author Topic: Creat Numbers with reactor  (Read 3410 times)

0 Members and 1 Guest are viewing this topic.

xianaihua

  • Guest
Creat Numbers with reactor
« on: December 12, 2009, 03:34:02 AM »
Hi all..
I write a program that Creat  Numbers with reactor,Annotations can be automatically increment the  numbers with reactor.However, still some problems.

I very much hope all my friends to guide! My english is poor,Please bear with us.
thank you.

lihuaili
Code: [Select]
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  AUTHOR:  lihuaili, October 2009.   VERSION:   v 1.0                          ;;
;;...............................................................................;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;

(vl-load-com)
       
(setq *ActiveDocument*
       (vla-get-ActiveDocument
         (vlax-get-acad-object)
       ) ;_ end of vla-get-ActiveDocument
) ;_ end of setq
(setq *ModelSpace*
       (vla-get-ModelSpace
         *ActiveDocument*
       ) ;_ end of vla-get-ModelSpace
) ;_ end of setq
(setq *AcadBlock*
       (vla-get-blocks
         *ActiveDocument*
       ) ;_ end of vla-get-blocks
) ;_ end of setq

;;;Creat Num block with attribute
(defun Creat_Num_block (TextHight    radius   /
cirPnt      blockObj   circleObj
attributeObj
       )
  (setq cirPnt (list radius radius 0.0))
  (setq blockObj     (vla-add *AcadBlock*
      (vlax-3d-point cirPnt)
      "num"
     )
circleObj    (vla-AddCircle
       blockObj
       (vlax-3d-point cirPnt)
       radius
     )
attributeObj
     (vla-AddAttribute
       blockObj
       TextHight
       acAttributeModeVerify
       ""
       (vlax-3d-point cirPnt)
       "nums"
       ""
     )
  )
  (vla-put-Alignment attributeObj acAlignmentMiddle)
  (if (> (setq v (distof (substr (getvar "acadver") 1 3))) 16.2)
    (vla-put-TextAlignmentPoint
      attributeObj
      (vlax-3d-point cirPnt)
    )
  )
  (vla-Update attributeObj)
)

(defun draw_leader (pt1 pt2 / leaderobj) ;draw leader
  (command "leader" pt1 pt2 "f" "st" "f" "a" "" "" "n")
  (setq leaderobj (vlax-ename->vla-object (entlast)))
  (vla-put-ArrowheadType leaderobj acArrowDotSmall)
  (vla-Update leaderobj)
  leaderobj
)

;;;set Attributes
(defun SetAtts (Obj Lst / AttVal)
  (mapcar
    '(lambda (Att)
       (if (setq AttVal (cdr (assoc (vla-get-TagString Att) Lst)))
(vla-put-TextString Att AttVal)
       )
     )
    (vlax-invoke Obj "GetAttributes")
  )
  (vla-update Obj)
  (princ)
)

;;;Get numbers of block reference Object  in ModelSpace
(defun Get_blkRef_Num (blkRef_name / count objEnt)
  (setq count 0)
  (vlax-for objEnt *ModelSpace*
    (if (equal (vla-get-ObjectName objEnt) "AcDbBlockReference")
      (progn (if (equal (vla-get-Name objEnt) blkRef_name)
       (setq count (1+ count))
     )
      )
    )
  )
  count
)

;;;check if have "num" block exist
(defun check_num_block (/)
  (if (ssget "X"
     '((0 . "INSERT")
       (2 . "num")
      )
      )
    T
    nil
  )
)

;;;--------------------------------------------------------------------;
;;;       Function:  set-params-obj                                    ;
;;;                                                                    ;
;;;    Description:  This function sets the parameters required        ;
;;;                  to associate a dimension object               .   ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;      vla-blk_bef = a valid vla blk_bef object.                     ;
;;;      vla-leader = a valid vla leader object.                       ;
;;;                                                                    ;
;;; Returned Value:  coordinates to the leader object.                 ;
;;;                                                                    ;
;;;          Usage:                                                    ;
;;;              (set-params-obj                                       ;
;;;                 vla-blk_bef  vla-leader                            ;
;;;               )                                                    ;
;;;--------------------------------------------------------------------;
(defun set-params-obj
       (vla-blk_bef vla-leader / ins-pnt lead-pnt1 lead-pnt2 sca rad)
  (if (and (= (type vla-blk_bef) 'VLA-OBJECT)
   (vlax-read-enabled-p vla-blk_bef)
      )
    (progn
      (setq ins-pnt (vla-get-InsertionPoint vla-blk_bef))
      (if (eq (type ins-pnt) 'VARIANT)
(if (> (vlax-variant-type ins-pnt) 8192)
  (setq
    ins-pnt (vlax-safearray->list (vlax-variant-value ins-pnt))
  )
)
      )
      (setq sca (vla-get-XScaleFactor vla-blk_bef)
    rad         (vlax-ldata-get vla-blk_bef "radius")
    lead-pnt1 (vlax-curve-getstartpoint vla-leader)
    lead-pnt2 (polar ins-pnt (angle ins-pnt lead-pnt1) (* sca rad))
    Coordinates (append lead-pnt1 lead-pnt2)
      )
    )
  )
)
;;;--------------------------------------------------------------------;
;;;       Function:  UPDATE-PARAMETER-MDIM                             ;
;;;                                                                    ;
;;;    Description:  This function is responsible for updating a       ;
;;;                  vla-object's parameter.                           ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;         vla-obj = a valid vla object.                              ;
;;;        par-name = a parameter name.                                ;
;;;       par-value = a new parameter value                            ;
;;;                                                                    ;
;;; Returned Value:  A vla object.                                     ;
;;;                                                                    ;
;;;          Usage:                                                    ;
;;;              (update-parameter-mdim                                ;
;;;                 vla-obj  par-name par-value                        ;
;;;               )                                                    ;
;;;--------------------------------------------------------------------;
(defun update-parameter-mdim (vla-obj par-name par-value)
  (if (and (= (type vla-obj) 'VLA-OBJECT)
   (vlax-write-enabled-p vla-obj)
   (not (equal (vlax-get vla-obj par-name) par-value))
      )
    (vlax-put vla-obj par-name par-value)
  )
)

;;;--------------------------------------------------------------------;
;;;       Function:  UPDATE-LEADER                                     ;
;;;                                                                    ;
;;;    Description:  This function updates the "coordinate" property   ;
;;;                  for the leader object.                            ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;         notifier = a valid vla object.                             ;
;;;         obj-list = a list of vla object.                           ;
;;;                                                                    ;
;;; Returned Value:  An updated leader object.                         ;
;;;                                                                    ;
;;;          Usage:                                                    ;
;;;              (update-leader                                        ;
;;;                   notifier obj-list                                ;
;;;               )                                                    ;
;;;--------------------------------------------------------------------;
(defun update-leader
     (notifier obj-list / vla-blk_bef vla-leader)
  (setq vla-blk_bef (nth 0 obj-list)
vla-leader  (nth 1 obj-list)
  )
  (if (set-params-obj vla-blk_bef vla-leader)
    (update-parameter-mdim vla-leader "Coordinates" Coordinates)
  )
)

;;;--------------------------------------------------------------------;
;;;       Function:  reactor-leader_blk_bef                           ;
;;;                                                                    ;
;;;    Description:  This function will be called inside               ;
;;;                  :vlr-modified event.                              ;
;;;                                                                    ;
;;;                  Required Functions:                               ;
;;;                         update-leader-for-blk_bef                  ;
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;        notifier = a valid vla object. Filled in by the calling     ;
;;;                   reactor.                                         ;
;;;         reactor = a valid vlr object reactor. Filled in by the     ;
;;;                   calling reactor.                                 ;
;;;        arg-list = argument list filled in by the calling reactor.  ;
;;;                   Filled in by the calling reactor.                ;
;;;                                                                    ;
;;; Returned Value:  A valid vla object.                        ;
;;;                                                                    ;
;;;          Usage:  Intended to be called from a reactor call back.   ;
;;;       (reactor-leader_blk_bef notifier reactor arg-list)          ;
;;;--------------------------------------------------------------------;
(defun reactor-leader_blk_bef (notifier reactor arg-list)
  (update-leader notifier (vlr-data reactor))
)

;;;--------------------------------------------------------------------;
;;;      main Function                                 ;
;;;--------------------------------------------------------------------;

(defun c:draw_numbers (/   vla-leader TextHight radius
       sca   loop1      loop2 pt0
       vla-blkref count      count_str att_lst
       vla-leader sp      source Points
       reactor
      )
  (setvar "CMDECHO" 0)
  (setq TextHight 5
radius 5
sca 1
loop1 T
  )

  (if (not (check_num_block))
    (Creat_Num_block TextHight radius)
  )
  (while loop1
    (if (setq pt0
       (getpoint
"\nPick Start Point(Right-click or Enter Exit):"
       )
)
      (progn
(setq vla-blkref
(vla-InsertBlock
   *ModelSpace*
   (vlax-3d-point pt0)
   "num"
   sca
   sca
   sca
   0
)
      count (Get_blkRef_Num "num")
      count_str (itoa count)
      att_lst (list (cons '"nums" count_str))
      loop2 T
)
(SetAtts vla-blkref att_lst)
(setq vla-leader (draw_leader pt0 (polar pt0 0 0.001)))

(prompt "\nPick Number Insert Point:")

(while loop2
  (setq sp     (grread T)
source (car sp)
sp     (cadr sp)
  ) ;_ end setq
  (cond ((= source 5)
(vla-put-InsertionPoint vla-blkref (vlax-3d-point sp))
(setq
   Points
    (vlax-safearray-fill
      (vlax-make-safearray
vlax-vbdouble
'(0 . 5)
      )
      (append pt0
      (polar sp (angle sp pt0) (* radius sca))
      )
    )
)

(if (> (distance sp pt0) (* radius sca))
   (vla-put-coordinates vla-leader Points)
)
)
(t
(progn (setq loop2   nil
      obj-lst (list vla-blkref vla-leader)
)
(vlax-ldata-put vla-blkref "radius" radius)

(function reactor-leader_blk_bef)
(setq reactor
       (VLR-Object-reactor
obj-lst
obj-lst
'((:vlr-modified . reactor-leader_blk_bef))
       )
)
)
)
  )
)
      )
      (setq loop1 nil)
    )
  )
  (princ)
)

xianaihua

  • Guest
Re: Creat Numbers with reactor
« Reply #1 on: December 12, 2009, 03:45:19 AM »
This is a demonstration program

xianaihua

  • Guest
Re: Creat Numbers with reactor
« Reply #2 on: December 12, 2009, 04:01:12 AM »
Problems:When the drag leader moves, the reactor does not work, as shown below

Crank

  • Water Moccasin
  • Posts: 1503
Re: Creat Numbers with reactor
« Reply #3 on: December 12, 2009, 07:34:52 AM »
Modifying the block seems to be the only trigger to update the leader. I think you have do the same thing when you modify the leader.
But why don't you use a mleader for this?
Vault Professional 2023     +     AEC Collection

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Creat Numbers with reactor
« Reply #4 on: December 12, 2009, 11:24:02 AM »
For more help look at this routine.
http://www.theswamp.org/index.php?topic=29245.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

fixo

  • Guest
Re: Creat Numbers with reactor
« Reply #5 on: December 12, 2009, 03:37:35 PM »
Hi all..
I write a program that Creat  Numbers with reactor,Annotations can be automatically increment the  numbers with reactor.However, still some problems.

I very much hope all my friends to guide! My english is poor,Please bear with us.
thank you.

lihuaili


Try use AddLeader instead of (command "leader"...)

~'J'~

xianaihua

  • Guest
Re: Creat Numbers with reactor
« Reply #6 on: December 12, 2009, 08:04:31 PM »
thanks Crank,CAB,fixp

However, your understanding and my purpose is not the same.

In the mechanical design of the assembly, I have often marked Part Number
As shown in the following example

xianaihua

  • Guest
Re: Creat Numbers with reactor
« Reply #7 on: December 12, 2009, 08:32:57 PM »
hi ~'J'~

I have used AddLeader instead of (command "leader"...),but don't work.

Code: [Select]

(defun gp:list->variantArray (ptsList / arraySpace sArray)

  (setq arraySpace
(vlax-make-safearray
  vlax-vbdouble
  (cons 0
(- (length ptsList) 1)
  )
)
  )
  (setq sArray (vlax-safearray-fill arraySpace ptsList))

  (vlax-make-variant sArray)
)


(setq mspace (vla-get-modelspace
      (vla-get-activedocument (vlax-get-acad-object))
    )
)


(setq apt (getpoint "First point: "))

(setq pt (getpoint "Second point: " apt))
(setq points (append apt pt))


(setq VLADataPts (gp:list->variantArray points))

(setq
  leaderobj
   (vla-AddLeader
     mspace
     VLADataPts
     nil
     acLineWithArrow
   )
)




xianaihua

  • Guest
Re: Creat Numbers with reactor
« Reply #8 on: December 12, 2009, 09:28:21 PM »
The following is written in I use VBA

Aerdvark

  • Guest
Re: Creat Numbers with reactor
« Reply #9 on: December 14, 2009, 01:58:16 AM »
Hello xianaihua,

I have another interest: how do you make those gif's?
If possible, I would like to have such program too.

Tnx.

xianaihua

  • Guest
Re: Creat Numbers with reactor
« Reply #10 on: December 14, 2009, 05:52:35 AM »
Hello xianaihua,

I have another interest: how do you make those gif's?
If possible, I would like to have such program too.

Tnx.

Hi,Tnx.
I use Snagit.
http://www.techsmith.com/products.asp

Aerdvark

  • Guest
Re: Creat Numbers with reactor
« Reply #11 on: December 16, 2009, 02:27:11 AM »
Hi,

I have Snagit also, but I don't know if I can make those animated gifs?
Can you tell me how you "set up the program".

I know I am a bit off topic so maybe PM me...

Tnx.

xianaihua

  • Guest
Re: Creat Numbers with reactor
« Reply #12 on: December 16, 2009, 09:30:43 AM »
Hi,Aerdvark
I generally use Snagit to capture as avi format, edited with Ulead GIF or gif Movie gear, and then save it as gif format
« Last Edit: December 16, 2009, 09:41:10 AM by xianaihua »