CAD software discussion forum > CAD > Block -XScaleFactor,YScaleFactor (VBA)

Block -XScaleFactor,YScaleFactor (VBA)

Rank: 1

Marijan Glavac

Newbie

posts: 0

Registered: 2011-6-5

Message 1 of 11

22-03-2011 05:02 . am | View his/her posts only
Hi,

I try to change size of specific block through command XScaleFactor,YScaleFactor.

Code (ZWCAD 2011,VBA):
Private Sub cdOK_Click()
Dim EntObj As ZwcadEntity
Dim blockObj As ZwcadBlockReference
Dim X, Y As Double
For Each EntObj In ThisDocument.ModelSpace
With EntObj
If EntObj.EntityType = zcBlockInsert Then
Set blockObj = EntObj
If blockObj.Name = StartBlok Then
X = 1
Y = 1
blockObj.XScaleFactor = X
blockObj.YScaleFactor = Y
blockObj.Update
End If
End If
End With
Next EntObj
Debug.Print "==>KRAJ OK"
End Sub


Results is that specific block (StartBlok) has XScaleFactor and YScaleFactor as I want (in this case X=1,Y=1)on drawing checking by Properties.


Problem is that size of that block is not change. It is only changed when I manually do that (Change properties -Parameter YscaleFactor.



It is possible to change XScaleFactor and YScaleFactor of block thorough VBA with effect ?

Regards,

MaGla

Rank: 1

OldForumPost

Newbie

posts: 0

Registered: 2012-1-14

Message 2 of 11

 Block -XScaleFactor,YScaleFactor (VBA)
23-03-2011 12:53 . am | View his/her posts only


From the code, it seems that there is problem in REGEN mechanism in ZWCAD. Anyway, try to add this line to the end:

ThisDocument.Regen zcAllViewports

Rank: 1

Marijan Glavac

Newbie

posts: 0

Registered: 2011-6-5

Message 3 of 11

23-03-2011 05:08 . am | View his/her posts only

Thanks Daniel,but Cry


Unfortunately, zero points.




It works only with block without attributes.


If I have block only with attributes there will be no changes at all For block (graphic + attribute) it will change only graphic.





How to change size of text in block attribute ?

Rank: 1

OldForumPost

Newbie

posts: 0

Registered: 2012-1-14

Message 4 of 11

23-03-2011 12:00 . pm | View his/her posts only

[QUOTE=magla]

Thanks Daniel,but Cry


Unfortunately, zero points.




It works only with block without attributes.


If I have block only with attributes there will be no changes at all For block (graphic + attribute) it will change only graphic.





How to change size of text in block attribute ?


are you interesting with lisp solution ?
j.

Rank: 1

Marijan Glavac

Newbie

posts: 0

Registered: 2011-6-5

Message 5 of 11

23-03-2011 07:55 . pm | View his/her posts only
Yes, LISP will be OK

Rank: 1

OldForumPost

Newbie

posts: 0

Registered: 2012-1-14

Message 6 of 11

24-03-2011 12:04 . pm | View his/her posts only

[QUOTE=magla]Yes, LISP will be OK
(defun c:SEL (/ SS O#)
(vl-load-com)
(if (setq SS (ssget "_X" '((0 . "INSERT")(2 . "blockname"))))
(foreach % (jk:SSX_SS->List SS)
(if (vlax-write-enabled-p (setq O# (vlax-ename->vla-object %)))
(progn
(vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
(vla-put-XScaleFactor O# 2) ;;; scale X
(vla-put-YScaleFactor O# 2) ;;; scale Y
(vla-put-ZScaleFactor O# 2) ;;; scale Z
(vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
)
)
)
(princ "'n** Nothing sleectedo. **")
)
(princ)
)
; ============================================================ ;
; Convert selection set to list of ENAME ;
; ============================================================ ;

(defun jk:SSX_SS->List (sel / n l)
(repeat
(setq n (sslength sel))
(setq n (1- n)
l (cons (ssname sel n) l)
)
)
)

Rank: 1

Marijan Glavac

Newbie

posts: 0

Registered: 2011-6-5

Message 7 of 11

25-03-2011 07:28 . pm | View his/her posts only
Jason,

after :
Command: c:sel

Always get -Nothing sleectedo

What I'm doing wrong?

Rank: 1

OldForumPost

Newbie

posts: 0

Registered: 2012-1-14

Message 8 of 11

28-03-2011 02:11 . am | View his/her posts only

[QUOTE=magla]Jason,

after :
Command: c:sel

Always get -Nothing sleectedo

What I'm doing wrong?

this one will be more user frindly
(defun c:SEL (/ OB OB# EN X Y)
(vl-load-com)
(if (setq OB (entsel "'nSelect block to change XY scale: "))
(if (= (cdr (assoc 0 (entget (setq EN (car OB))))) "INSERT")
(if (not (kr:BLK_CheckIfXref (setq OB# (vlax-ename->vla-object EN))))
(if (vlax-write-enabled-p OB#)
(if
(and
(setq X (getreal "'nEnter X scale factor: "))
(setq y (getreal "'nEnter Y scale factor: "))
)
(progn
(kr:SYS_StartUndo)
(if (vlax-Property-Available-P OB# 'XEffectiveScaleFactor)
(progn
(vla-put-XEffectiveScaleFactor OB# X)
(vla-put-YEffectiveScaleFactor OB# Y)
)
(progn
(vla-put-XScaleFactor OB# X)
(vla-put-YScaleFactor OB# Y)
)
)
(kr:SYS_EndUndo)
)
(princ "'n** Invalid input **")
)
(princ "'n** Object on locked layer **")
)
(princ (strcat "'n** Caution! '"" (kr:BLK_GetBlockName OB#) "'" is an externally referenced block **"))
)
(princ "'n** Selected item not an INSERT ** ")
)
(princ "'n** Nothing selected **")
)
(princ)
)

; ============================================================ ;
; Retrieves pointers to the active document ;
; ============================================================ ;

(defun kr:ACX_ADoc ()
(or
*kr-ADoc
(setq *kr-ADoc (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
)
*kr-ADoc
)

; ============================================================ ;
; Check if selected block as an XREF ;
; Blk - VLA block reference object ;
; ============================================================ ;

(defun kr:BLK_CheckIfXref (Blk)
(eq
(vla-Get-IsXref
(vla-Item
(vla-Get-Blocks (kr:ACX_ADoc))
(vla-Get-Name Blk)
)
)
:vlax-true
)
)

; ============================================================ ;
; Get block name ;
; Blk - VLA block reference object ;
; ============================================================ ;

(defun kr:BLK_GetBlockName (Blk)
(if (vlax-Property-Available-P Blk 'EffectiveName)
(vla-Get-EffectiveName Blk)
(vla-Get-Name Blk)
)
)

; ============================================================ ;
; Start undo mark ;
; ============================================================ ;

(defun kr:SYS_StartUndo ()
(vla-StartUndoMark (kr:ACX_ADoc))
)

; ============================================================ ;
; End undo mark ;
; ============================================================ ;

(defun kr:SYS_EndUndo ()
(vla-EndUndoMark (kr:ACX_ADoc))
)

(princ)

Rank: 1

Marijan Glavac

Newbie

posts: 0

Registered: 2011-6-5

Message 9 of 11

29-03-2011 02:57 . pm | View his/her posts only


Thanks

Rank: 1

noys

Newbie

posts: 0

Registered: 2011-6-1

Message 10 of 11

11-05-2011 04:19 . am | View his/her posts only
I encountered this many times. the undo comes in a batch. why is it happening?? I already done so many lines and text by just making use of undo once one batch of what i've done is lost. so I need to repeat again what I already did. A waste of time especially in a rush.

Rank: 1

OldForumPost

Newbie

posts: 0

Registered: 2012-1-14

Message 11 of 11

 Block -XScaleFactor,YScaleFactor (VBA)
23-03-2011 12:53 . am | View his/her posts only
Hi noys,

Are you having this problem in ZWCAD 2011? is it frequently happen? is there any special drawings that always has this problem?
The more info you provide, we can better solve the problem in time, thanks!
See also