PDA

View Full Version : acad2002: Blockreference and attribute rotation



Sandieslover
04-06-2005, 04:11 AM
Hi forum,
I want to create some code that changes the rotation of a block reference.
I also would like to have some code that changes the rotation of block attributes and the justification for the blocks selected.

I'm a bit familiar with VBA in Excel and Word, but VBA for acad is new to me.

Please can somebody help me out?

Kind regards,
Sandieslover

Tommy
04-06-2005, 06:25 AM
Hi Sandieslover,

I have 2000, but am willing to help out as much as I can. I am currently working on a project looking for blocks and doing manipulation with them. I'll be back with what I find :)

Tommy
04-06-2005, 10:52 AM
Rotate block reference

Sub RotateBlock()
Dim A As AcadDocument
Set A = ActiveDocument
Dim entry As AcadEntity
For Each entry In A.ModelSpace
If TypeOf entry Is AcadBlockReference Then
Set E = entry
On Error Resume Next 'autocad doesn't like it when you explode the actual block and not the insert
E.Rotate E.InsertionPoint, 32
Err.Clear
On Error GoTo 0
Set E = Nothing
End If
Next
End Sub


Sorry but I am unclear as to what you want to do here:
I also would like to have some code that changes the rotation of block attributes and the justification for the blocks selected.

Sandieslover
04-07-2005, 06:01 AM
Hi Tommy,
thanx in advance for the time and trouble you make to help me out.
Your code works! But is not quite what I'm looking for, so on your Q, what I want to do the followin:
I'm an electrical draftsman in which I have to create electrical building layouts with lighting, socket outlets etc. On this particular project we have to work with the principals drawings, standards and symbols. The problem is that the attributes of a block, for instance a socket outlet on a righthand wall will have another attribute justification than on the lefthand wall.
As the socket outlet contains information about it's feederpanel, feeder group, tagnumber, load, etc. that the principal extracts from the drawing, i'm not allowed to modify and/or add attributes. So for a few dozen sockets, lighting fixtures and so (for each drawing) I will have to ajust the rotation of the block, or in other situations just the rotation of the attributes of that block and often the left or right alignment too.

Wow, it's become quite a story, hopefully you understand my meaning with the rotation of the block or it's attibutes, and can you help me out with some code to do just that for me.
My goal is to select the symol or symbols to be adjusted and than run the code for that action.

Many thanx so far,
Regards,
Sandieslover

Tommy
04-07-2005, 06:27 AM
Can you post a dwg for me to play with? That way I can get it right just like you want. My blocks are structural shapes the attributes are load reactions so I am thinking it would be easier with your dwg.

Good I would rather work with a selection set. So to start with you select the block(s) answer a few questions and it gets fixed. BTW is this 3D?

MikeS
04-08-2005, 11:16 AM
I'm still a beginner, but here's a routine I wrote to rotate a single attribute. Maybe it will help you out?:dunno

Public Sub rotateattribute()
Dim presrot As Variant
Dim objent As AcadEntity
Dim varpnt As Variant
Dim varbase As Variant
Dim vardisp As Variant
Dim varsubids As Variant
Dim varmatrix As Variant
Dim strval As String
Dim strkeys As String
Dim strprompt As String
strprompt = "Pick Attribute to rotate"

On Error GoTo break
ThisDrawing.Utility.GetSubEntity objent, varpnt, varmatrix, varsubids, strprompt
If TypeOf objent Is AcadAttributeReference Then
varbase = objent.InsertionPoint
presrot = objent.Rotation
Err.Clear
Else: GoTo break
End If
strprompt = "Specifiy rotation angle:"
vardisp = ThisDrawing.Utility.GetAngle(varbase, strprompt)
objent.Rotation = vardisp
break:
End Sub

Sandieslover
04-11-2005, 01:05 AM
Hi,

no, it's not 3D.
'cause of some confidentiality I've created a sampledrwaing with some blocks.

Thanx so far,

Sandieslover

Sandieslover
04-11-2005, 07:26 AM
Hi dunno,

this helps.
With this I can try to figure out the rest, such as adjusting the text alignment and to toggle the visibility of some attributes.
Thanx.

Regards,
Sandieslover

p.s. if someone already knows how to do this... please give me an e-mail.

lucas
06-07-2005, 03:15 PM
Rotate block reference

Sub RotateBlock()
Dim A As AcadDocument
Set A = ActiveDocument
Dim entry As AcadEntity
For Each entry In A.ModelSpace
If TypeOf entry Is AcadBlockReference Then
Set E = entry
On Error Resume Next 'autocad doesn't like it when you explode the actual block and not the insert
E.Rotate E.InsertionPoint, 32
Err.Clear
On Error GoTo 0
Set E = Nothing
End If
Next
End Sub




Hi Tommy,
I have a couple of questions about this routine if you don't mind...
First, it selects all blocks on a sheet, is there a way to select blocks to rotate using this code. The other question I have is where does it get the degree of rotation, is it from this line of code:
E.Rotate E.InsertionPoint, 32
and if it is, does this mean it rotates it 32 degrees?

Tommy
06-08-2005, 06:00 AM
Hi Lucas! :)

1 It's possible, check for a name, or insertion points (above, below, the same) either way, that was modified from a routine I wrote to explode all blocks, puge the doc export to dxf and save so it is kinda rough, I was setting up for something else.

2 Yes

3 Yes

What are you trying to do?

lucas
06-08-2005, 07:34 AM
Hi Lucas! :)

What are you trying to do?
Hello Tommy,
I am really just trying to understand how some of the vba code for Cad works. Its really quite different from excel vba and I don't have any real experience in either.

I yoinked your code from a different post for opening a cad file and set up a directory of symbol files and set up a toolbar with a button to open each symbol file. Its going to be handy for me to just open a commonly used file by just clicking on a button. Every keystroke saved in CAD helps....

As far as the code on this post, rotating blocks, I sometimes have to rotate one or more blocks a consistant used angle. I found your code interesting for the same reason I mentioned above, to save keystrokes. Thought I could be able to select one or more blocks, and rotate them the predetermined angle by just clicking the button...insertion point on the blocks can be changed so thats not an issue.

Glad to see your still with the forum. Hope things are well in Texas, get ready for summer heat its coming our way

Tommy
06-08-2005, 08:31 AM
It was a 106 degrees F in my truck yesterday, too early for that much heat :)

You could rotate each block from a selection set :) pipe in (or set) the constant rotaion angle.
I have some better stuff in lisp, it shows the block (as a slide) allows you to pick the block insert with insertion point (could be scaled if needed) and pick the next block, I got most of it out of Cadence, and of course butchered it to suit my needs :), a lot of it was coded by a friend, but he got to busy and asked me to finish it. See attached for the user interface.

lucas
06-08-2005, 07:48 PM
Hey Tommy that looks pretty handy. You can add and remove blocks from it? Speaking for myself, its easier using lisp with AutoCAD than vba.
I use several Lisp routines but I didn't code them. I have been to cadence and downloaded most of what they have to try. I have one I use for steel shapes thats really handy, you probably have it or something better. Its called "Steel"

Tommy
06-09-2005, 06:07 AM
Yes I have a similar version, we have some lisp routines that draws all of the structural shapes in plan, elevation, section. It used to be menu poicks but when acad came out with dcl we moved it to forms.

You can add, subtract blocks as you wish, we have over a 1000 blocks in it, the preview is a slide, so you would have a slide and a drawing in the directory.

lucas
06-15-2005, 04:44 PM
Thanks Tommy for going above and beyond to help me. The script is working out great. Got me a new txt editor so I can see the carriage returns:doh:
Catfish are spawning here....come help me get these things in the boat!