Author Topic: Q on Attributes and 2008  (Read 6283 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Q on Attributes and 2008
« Reply #15 on: March 14, 2008, 05:09:04 AM »
<snip>I have now seen the resulting drawing when these blocks are programatically (see Keith's code) placed in a new file.
The weird thing is that all of the attributes are rotated to 0°.
Further weirdness... if I copy a block and explode it the attributes then rotate to the correct rotation (some 0° and some at 90°).
<snip>

code ??
and drawing ?
may help to resolve the problem.



I regularly rotate attributes from code in AC 2008 without any issues.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

hendie

  • Guest
Re: Q on Attributes and 2008
« Reply #16 on: March 14, 2008, 06:17:13 AM »
here's copy of the drawing I recieved from the user.


unfortunately, I don't have the code handy at this time

Crank

  • Water Moccasin
  • Posts: 1503
Re: Q on Attributes and 2008
« Reply #17 on: March 15, 2008, 08:24:23 AM »
Just looked at the drawing in 2008/2009, but I didn't see anything that could cause this.
I think it's the code. In 2008/2009 there is a bug in (entmod) if a text or attribute is annotative. I replaced all my entmod code in lisp with VL-commands. If you use (entmod), strange things are happening.

Because this is only happening in 2008, the only thing I can think of, is that it has something to do with an annotative text style. With annotative text it's possible to align the text with the current layout.
If they are using annotative text, you could check if this setting isn't turned on:
Without the code I can't guarantee this is causing your problem. I'm just thinking out lout. :)
« Last Edit: March 15, 2008, 08:36:17 AM by Crank »
Vault Professional 2023     +     AEC Collection

hendie

  • Guest
Re: Q on Attributes and 2008
« Reply #18 on: March 15, 2008, 08:52:55 AM »
thanks for the input Crank.
We don't use anything annotative but I'll check with the client and see what they are doing.

There's really nothing to do the code, it's pretty straightforward stuff

Code: [Select]
If AC.activedocument.ActiveSpace = AcModelSpace Then
     Set T3blk = AC.activedocument.ModelSpace.InsertBlock(InsPt, nBlk, Xold, Yold, Zold, 0)
Else
     Set T3blk = AC.activedocument.PaperSpace.InsertBlock(InsPt, nBlk, Xold, Yold, Zold, 0)
End If
    Dim CurrLO As String 'AcadLayout
        CurrLO = AC.activedocument.ActiveLayout.Name
        AC.activedocument.Blocks.Item(T3blk.Name).Name = T3blk.Name & "-" & CurrLO & "-" & Format$(Time, "HHMMSS") & Xz
then we grab the attributes and populate the new attributes with the old attribute information. Provided the new attribute isn't empty then we then nest a block in the new block

Code: [Select]
Case "NBL"
Natts(X).TextString = NBL
     If Trim(Natts(X).TextString) <> "" Then
          Set ArrBlk = AC.activedocument.Blocks.Item(T3blk.Name).InsertBlock(BaseIns, ARROW & "L.dwg", 1, 1, 1, (PI / 2 * 3))
     End If

The only time we interfere with the attributes is to push and pull information. There's no repositioning, no rotating or anything else.

But your suggestion is very intriguing... I have a felling that may prove fruitful... thanks again

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Q on Attributes and 2008
« Reply #19 on: March 15, 2008, 10:37:36 AM »
The funny thing about this is that the original block inserted by exactly the same code does not exhibit the issue ...

Let me try and explain it a little better ..
The program inserts blocks based on a user preseelction of styles, the attributes in these blocks are populated from data files of various types. In some instances, there are blocks where the data is empty or has all zeros. When this happens, the user may elect to switch the block to a different style, with the limited number of attributes as was populated in the firsst block insertion (i.e. where all attributes of a particular series is 0). So, we have another utility built in that allows the user to select the block to change. The program reads the atributes from the block and stores them, gets the rotation, scale, and insertion point of the block and stores them. Finally it inserts another block with the correct number of attributes (leaving out the series that had all zeros .. the geometry in the block is different too) and sets the rotation, scale, insertion point to the original block, populates the attributes on the new block, then deletes the old block.

On all versions of AutoCAD from R2000 to R2007 there has been no issue with rotated attributes, however, in 2008 it has reared its ugly head ... and like I said before .. the initial block does not have the problem, only the replacement one.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Q on Attributes and 2008
« Reply #20 on: March 20, 2008, 09:46:24 PM »
I have finally managed to resolve this issue. It seems a bug was introduced in the AutoCAD 2008 VBA interface.

Lets have a look at the issue and how to resolve it.

Issue:
When inserting blocks programmatically with VBA, any attached attribute references are rotated to 0 degrees.

Cause:
Many times after insertion of a block, the user may want to change the rotation of the block. Programmatically changing the rotation of a block with attributes will cause the attributes to take on the rotation angle of the passed argument to the rotation property of the block reference .. see code segment ..
Code: [Select]
'insert block at 0 degrees
Set T3blk = AC.activedocument.ModelSpace.InsertBlock(InsPt, nBlk, Xold, Yold, Zold, 0)
'rotate block to the value of Rold and all attribute references
'in that block are also rotated to the angle specified by Rold
T3blk.Rotation = Rold

Steps to recreate:
Insert a block at any prespecified rotation using VBA, then programmatically reset the rotation property of the block reference. All attributes will be rotated to the value specified as the rotation of the block reference.

Workaround:
1) Immediately issue a attsync command after programmatically rotating a block reference with attached attributes.
or
2) If at all possible, programmatically set the rotation angle of the block reference during the insertion process.
or
3) After rotating the block reference programmatically, step through each attribute and programmatically re-orient each attribute to the desired value. It may be necessary to retrieve the rotation of each attribute prior to setting the block reference rotation and apply the rotation difference applied to the block reference.

Solution:
The problem does not exhibit itself when utilizing the type library shipped with AutoCAD 2008 in AutoCAD 2007, i.e. set the reference to the AutoCAD 2008 type library for projects built in AutoCAD 2007. this would lead one to believe the issue is within the core of the program and not an issue with VBA or the implementation of the COM environment in AutoCAD 2008, rather a more dubious issue with regard to updating the attribute properties when programmatically resetting the value of the rotation of the block reference i.e. someone forgot to apply the rotation differential of the attributes when the rotation of the block reference is done via the COM interface. It will require a patch to correct the issue.


*edit*
Further testing reveals that the VLISP interface is affected by a variant of this issue as well. Using the following code to insert a block, then to subsequently rotate the block reference leaves the attributes in the original location and does not rotate the attributes with the block reference.

Code: [Select]
(defun c:test()
  (setq blname (getstring "\nBlock name (with attributes attached): "))
  (setq *acad* (vlax-get-acad-object))
  (setq *doc* (vlax-get-property *acad* 'ActiveDocument))
  (setq *modelspace* (vlax-get-property *doc* 'ModelSpace))
  (setq vlobj (vla-insertblock *modelspace* (list->variantArray(getpoint "\nInsertion point: ")) blname 1 1 1 0))
  (vlax-put-property vlobj 'Rotation 1.5708)
  (vla-update vlobj)
)

(defun 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)
)
« Last Edit: March 20, 2008, 10:37:31 PM by Keith™ »
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hendie

  • Guest
Re: Q on Attributes and 2008
« Reply #21 on: March 21, 2008, 05:12:39 AM »
yeah GO Autodesk..... just what we need. !
Can someone with 2008 raise this issue to Autodesk in a bug report?

KewlToyZ

  • Guest
Re: Q on Attributes and 2008
« Reply #22 on: July 10, 2008, 02:23:26 PM »
???????
Code: [Select]
;; add to mnl file:
;; (load "test2")
;;
;;
;; Place into button command or paste into command line
;;command: ^C^C_(test2 "Path/YourBlock")
(defun test2 (blname /)
  ;(setq blname (getstring "\nBlock name (with attributes attached): "))
  (setq ds (getvar "dimscale"))
  (setq *acad* (vlax-get-acad-object))
  (setq *doc* (vlax-get-property *acad* 'ActiveDocument))
  (setq *modelspace* (vlax-get-property *doc* 'ModelSpace))
 
  (setq insPoint(getpoint "\nInsertion point: "))
  (setq ang (getangle "\nRotation angle: "))
  (setq vlobj (vla-insertblock *modelspace* (list->variantArray insPoint) blname 1 1 1 ang))
  ;(setq vlobj (vla-insertblock *modelspace* (list->variantArray(getpoint "\nInsertion point: ")) blname 1 1 1 0)) 
  ;(setq ang (getpoint "\nPick point : "))
  ;(getorient ang "....Pick point: ")
  ;(vlax-put-property vlobj 'Rotation ang)
  (vla-update vlobj)
)

(defun 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)
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Q on Attributes and 2008
« Reply #23 on: July 10, 2008, 02:32:09 PM »
I am not where I can test the code, what does it do?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

KewlToyZ

  • Guest
Re: Q on Attributes and 2008
« Reply #24 on: July 10, 2008, 02:37:46 PM »
Lets me pick the rotation angle of the block on insert.
Attribute Text goes in normally annotative or not annotative it remains true to the original block.

Could be more dynamic of course but I'm just trying to figure out what your issue was.
I tried it in 2008 and 2009.

I'm trying to find an easy way to determine when to run a 180 degree rotation against attribute text according to the block insert angle. Mainly I wanted the text to only rotate 180 when it would appear upside down and do it programmatically for the user.
« Last Edit: July 10, 2008, 02:42:28 PM by KewlToyZ »

KewlToyZ

  • Guest
Re: Q on Attributes and 2008
« Reply #25 on: July 10, 2008, 02:44:59 PM »
I am using one to just manually set rotation to zero for any attribute.
But now I need to come up with a dynamic way to replace or check against the angle from pause in the insert, check the angle < 0 or angle > 180 then rotate the text only in that case at a relative rather than absolute 180.
For example:
Code: [Select]
(defun sensor (blk / inspt ds *error* save_sys_vars restore_sys_vars )

;==========================================================================================================================================Turn off command line responses
    ;(command "CMDECHO" 0) ;DO NOT CHANGE THIS LINE
;==========================================================================================================================================
;=========================================================================================
;;         L o c a l   F u n c t i o n s      
;=========================================================================================
;; error function & Routine Exit
(defun *error* (msg)
  (if
    (not
      (member
        msg
        '("console break" "Function cancelled" "quit / exit abort" "")
      )
    )
     (princ (strcat "\nError: " msg))
  )   ; endif
  (restore_sys_vars); reset vars
)

;; Function to save system variables in global variable
;=========================================================================================
(defun save_sys_vars (lst)
  (setq *sysvarlist* '())
  (repeat (length lst)
    (setq *sysvarlist* (append *sysvarlist* (list (list (car lst) (getvar (car lst))))))
    (setq lst (cdr lst))
  )
)
 
;; Function to reset system variables
;=========================================================================================
(defun restore_sys_vars ()
  (repeat (length *sysvarlist*)
    (setvar (caar *sysvarlist*) (cadar *sysvarlist*))
    (setq *sysvarlist* (cdr *sysvarlist*))
  )
)
;=========================================================================================
; Begin conditions
;=========================================================================================
(save_sys_vars '("clayer" "osmode" "orthomode" "autosnap" "polarang" "snapang")) ; Get User Settings
;=========================================================================================

;=========================================================================================
; Set Variables
;=========================================================================================

(setq ds (getvar "dimscale"))
(setq usersnaps (getvar "osmode")) ; -----------------------Get User Osmode Settings
(setq userlayer (getvar "clayer")) ; -----------------------Get User Layer Settings
(setq userpol (getvar "polarang")) ; -----------------------Get User Polar Angle Settings
(setq userauto (getvar "autosnap")) ; -----------------------Get User Polar Mode Settings
 
(setvar "osmode" 695)
(setvar "autosnap" 13)
(command "polarang" 15)
;==========================================================================================================================================Control Line Scaling
(command "PSLTSCALE" 0)
(command "MSLTSCALE" 0)
(command "LTSCALE" sc)
;==========================================================================================================================================

(prompt "\nMSpace & PSpace LTScale Varaibles set to 0!! Defaults to LTSCALE settings now!")
(while
(princ blk)
(setq inspt(getpoint "\nSelect Area or Wall (Area, Line, Polyline, Arc, Circle) ESC to EXIT:"))
 

(command "Expert" "1")
(LRS "E-LITE-DEVC")
(command "Expert" "0")
(prompt "\n E-LITE-DEVC layer set!!")
(setvar "ATTREQ" 0)
(command "-insert" blk "s" ds inspt pause)
(setq en (entlast))
  (while
    (setq en (entnext en))
     (setq ed (entget en))
     (if
       (equal (cdr (assoc 0 (entget en))) "ATTRIB")
(progn
  (setq ed ; rotate attribute to 0
(subst (cons 50 0)
(assoc 50 ed)
ed
)
  )
(entmod ed)
(entupd en)
)
)
) ;end attribute while loop
) ;end routine while loop
(command "osmode" usersnaps); -----------------------Return User Osmode Settings
(command "clayer" userlayer); -----------------------Return User Layer Settings
(command "polarang" userpol)
(command "regen")
(prompt "\n Junction Box routine Osnaps & Layer settings Returned.")
;==========================================================================================================================================Turn off command line responses
  ;(command "CMDECHO" 1) ;DO NOT CHANGE THIS LINE
;==========================================================================================================================================(*error* "") ; restore variables
(princ)
)
But I want the attributes to rotate 180 to their relative position, not an absolute 180.
I wondered if the dxf codes will prevent me from accomplishing.
« Last Edit: July 10, 2008, 03:01:29 PM by KewlToyZ »

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Q on Attributes and 2008
« Reply #26 on: July 10, 2008, 03:04:07 PM »
We had no problems setting the attributes to 0 deg. they would do that automagically whenever we would apply any changes to the block. Changing the attribute independently still works, but rotating the block after the fact does not rotate the attribute. It used to work pre-2008, whenever you programmatically changed a block rotation angle, the attributes changed as well. Now the attributes must be rotated manually as well as the block.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie