2008-08-08

5 Minutes Of Fame

I recently had some of my code posted on Cadalyst. I am posting it here for those of you who may need to copy attributes from one block to another block. We do this semi-often with various title blocks from customers and it comes in handy for "copying" information around. Enjoy.


Public Sub UserCopyAttsFromBlkToAnotherBlk()
'------------------------------------------------------------------------------
'user selects block and then selects attributed block to match to
'
'------------------------------------------------------------------------------
Dim vAtts As Variant
Dim vAtts2 As Variant
Dim sPrompt As String
'''''''''''''''''''''''''''''''''''''''
On Error GoTo ErrHandler

sPrompt = "Select Source Attributed Block: "
vAtts = UserGetBlockWithAtts(sPrompt).GetAttributes

sPrompt = "Select Destination Attributed Block: "
vAtts2 = UserGetBlockWithAtts(sPrompt).GetAttributes

Call CopySameAttsFromBlkToBlk(vAtts, vAtts2)

ErrHandler:
Select Case Err.Number
Case 0
Case Else
Err.Clear
End Select
End Sub

Public Function UserGetBlockWithAtts(Optional sPrompt As String = _
"Select Attributed Block: ") As AcadBlockReference
'------------------------------------------------------------------------------
'
'
'------------------------------------------------------------------------------
Dim acObj As Object
Dim vPickPt As Variant
Dim sAtt As String
'''''''''''''''''''''''''''''''''''''''
On Error GoTo NOT_ENTITY

TRY_AGAIN:
ThisDrawing.Utility.GetEntity acObj, vPickPt, sPrompt
If acObj.ObjectName <> "AcDbBlockReference" Then
GoTo NOT_ENTITY
End If

If acObj.HasAttributes Then
Set UserGetBlockWithAtts = acObj
Else
MsgBox "This Block has no Attributes"
End If
Exit Function

NOT_ENTITY:
'If you click on space or do not select an entity, this error will be generated
If MsgBox("You have not selected a block with attributes.", vbOKCancel) = vbOK Then
Resume TRY_AGAIN
End If
End Function


Public Sub CopySameAttsFromBlkToBlk(ByVal vAtts1 As Variant, _
ByRef vAtts2 As Variant)
'------------------------------------------------------------------------------
'
'
'------------------------------------------------------------------------------
Dim l As Long
Dim m As Long
'''''''''''''''''''''''''''''''''''''''
For m = LBound(vAtts1) To UBound(vAtts1)
For l = LBound(vAtts2) To UBound(vAtts2)
If vAtts1(m).TagString = vAtts2(l).TagString Then
vAtts2(l).TextString = vAtts1(m).TextString
End If
Next l
Next m
End Sub

2008-08-05

Snappy Tabby

Catchy title (don't you think? .. anyway). Just a quick reminder (one of our users asked the other day), if you use multiple osnap types but it seems AutoCad has this uncanny way of picking the one you do not want first, you can toggle through your osnaps with the TAB key. Like I said, Snappy Tabby.

2008-07-17

Hold the presses...

Printing that is. A user's plot dialog in AutoCAD took at least a minute to appear. I thought it could be a page setup issue, but he was set to None, so no issue there. I thought about it, maybe his printers. Took a quick look and what do you know, he had printers that were obsolete and/or unreachable from his computer. We deleted them and poof, the dialog is fast again. I have heard the same issue can appear with old drivers and certain printers (update if necessary). Let the presses roll!

2008-06-25

My UG is stuck

Okay, my first UG NX post. Well, we have UG NX4 and TeamCenter and we open our UG files through TeamCenter. We have startup scripts but when I got to a certain point the Command window just hangs. It is the process UG_remote that is the culprit. I kill the process and then all is well. Not stuck. The cause of all this was a failed startup because all of our network licenses were used up. Good to know for next time.

2008-06-19

Unknown but not forgotten

What next! Today I was going along as usual and then my "CH" (PROPERTIES) command disappeared. "What in the world.." I get an "Command: _properties Unknown command "PROPERTIES" Not good (I think to myself). I go to Control Panel and do a "Repair Registry" on my AutoCAD install. Nope, no change. I then do a "Repair Install". Nope. Getting a little worried here. I do a reinstallation. Still nothing. Oh no I think to myself. Finally I find the solution. It is the DEMANDLOAD variable. I never think about it, so it never occurred to me. I type it in, it is set to 0, so I change it to 2 and "wahlah", I am known again. It's good not to be forgotten.

2008-06-14

When is a font not a font..

Hey, my drawing looks weird. I have text that uses ISOCP.SHX but now it looks "too wide". I check the style, but it is set correctly. What the... I check for the font file.. okay. What I finally do is reboot (an old IT favorite). Well what do you know, the style is back (get it..back in style) Okay, till next time. Also see 2010.08.02 for update

2008-05-13

reOrdination

What I meant to say was changing your ordinates (dimension that is). I was looking how to change an ordinate dimension's origin in VB but I found that there is no property for that. Rats. I came up with a side track to do it and I figured I would post it if you needed to reordinate also.

Private Sub SetOrdinateZeroPoint(ByVal sHandle As String, ByVal vPt As Variant)
'------------------------------------------------------------------------------
'Changes an ordinate dims origin
'Arguments: sHandle - handle of dim entity
' vPt - variant point of new origin
'Example: Call SetOrdinateZeroPoint(acEnt.Handle, vPt1)
'------------------------------------------------------------------------------
ThisDrawing.SendCommand "(setq dimEnt (entget (handent """ & sHandle & """)))" & vbCr
ThisDrawing.SendCommand "(entmod (subst '(10 " & vPt(0) & " " & vPt(1) & " 0.0) (assoc 10 dimEnt) dimEnt))" & vbCr
End Sub

2008-05-05

Exploding Mechanical Objects

I know that those who work with Mechanical can appreciate the Mechanical objects that it creates and how it makes life easier. But what if another client wants the drawings and does not want these proxy entities in the drawing. The method usually suggested is to tell them to get the object enabler or to manually explode those objects (which Mechanical does fairly well). I have created a macro to explode the Mechanical objects to their AutoCAD equivalents and I wanted to know if anyone had any interest on a posting of a compiled version. Let me know if there is any interest. Thanks.