Consulting

Results 1 to 15 of 15

Thread: acad2002: Blockreference and attribute rotation

  1. #1
    VBAX Regular Sandieslover's Avatar
    Joined
    Sep 2004
    Location
    Netherlands
    Posts
    14
    Location

    acad2002: Blockreference and attribute rotation

    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

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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

  3. #3
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Rotate block reference
    [VBA]
    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
    [/VBA]

    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.

  4. #4
    VBAX Regular Sandieslover's Avatar
    Joined
    Sep 2004
    Location
    Netherlands
    Posts
    14
    Location
    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

  5. #5
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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?

  6. #6
    VBAX Regular
    Joined
    Mar 2005
    Posts
    11
    Location
    I'm still a beginner, but here's a routine I wrote to rotate a single attribute. Maybe it will help you out?

    [VBA]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

    [/VBA]

  7. #7
    VBAX Regular Sandieslover's Avatar
    Joined
    Sep 2004
    Location
    Netherlands
    Posts
    14
    Location
    Hi,

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

    Thanx so far,

    Sandieslover

  8. #8
    VBAX Regular Sandieslover's Avatar
    Joined
    Sep 2004
    Location
    Netherlands
    Posts
    14
    Location
    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.

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Quote Originally Posted by Tommy
    Rotate block reference
    [VBA]
    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
    [/VBA]
    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?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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?

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Quote Originally Posted by Tommy
    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
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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.

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    Block Library

    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"
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  14. #14
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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.

  15. #15
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location

    Thanks

    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
    Catfish are spawning here....come help me get these things in the boat!
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •