×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to use customized toolbar item for a block insertion?

How to use customized toolbar item for a block insertion?

How to use customized toolbar item for a block insertion?

(OP)
Hi,friends,

   I'm using AutoCAD VBA to develop a module for drawing hydraulic circuit, and plan to make the block for every standard parts, such as pumps, valve. But now I get trouble on how to use the customized toolbar item to command the insertion of corresponding block? Thanks.

RE: How to use customized toolbar item for a block insertion?

here's my secret insert routine...enjoy

Public Function InsertBlkRef(ByVal sBlkName As String, _
Optional ByVal bExplode As Boolean = True, _
Optional ByVal iSpace As Integer = 0, _
Optional ByVal dScale As Double = 1#, _
Optional ByVal vInsPt As Variant, _
Optional ByVal dRot As Double = 0#, _
Optional ByVal bLastObj As Boolean = False) As AcadBlockReference
'------------------------------------------------------------------------------
'InsertBlkRef:  Defaults are:
'               EXPLODED
'               MODELSPACE
'               1:1 SCALE
'               0,0 INSERT POINT
'               0 ROTATION
'               True RETURN LAST EXPLODED ITEM (use after explode of block
'                   which reveals another block)
'Arguments:     sBlkName = path and/or filename (i.e. "someblock.dwg")
'               bExplode = insert exploded TRUE or not explode FALSE
'               iSpace(OPT) = 0 for paperspace and 1 (default) is modelspace
'               dScale(OPT) = scale, the same for X and Y
'               vInsPt(OPT) = insertion point, zero-zero if none given
'               dRot(OPT) = rotation in degrees (converted to radians
'                               within function), defaults to zero if not given
'Returns:       Block reference (if it is the only item in the block)
'------------------------------------------------------------------------------
Dim acBlkRef As AcadBlockReference
Dim dInsPt(0 To 2) As Double
Dim acBlkEnts
'''''''''''''''''''''''''''''''''''''''
On Error GoTo ErrHandler

'--------------------------------------------------------------------------
'Set insertion point. Set to 0,0 if none given
'--------------------------------------------------------------------------
If IsMissing(vInsPt) Then
    dInsPt(0) = 0#: dInsPt(1) = 0#: dInsPt(2) = 0#
Else
    dInsPt(0) = vInsPt(0)
    dInsPt(1) = vInsPt(1)
    dInsPt(2) = vInsPt(2)
End If

dRot = DegreesToRadians(dRot)
'--------------------------------------------------------------------------
'Check if need to add .dwg for pathed files
'--------------------------------------------------------------------------
If InStr(sBlkName, "\") And Not LCase(Right$(sBlkName, 4)) = ".dwg" Then
    sBlkName = sBlkName & ".dwg"
End If
'--------------------------------------------------------------------------
'Set space to insert into. Then insert drawing
'--------------------------------------------------------------------------
If iSpace = 1 Then
    Set acBlkRef = ThisDrawing.PaperSpace.InsertBlock(dInsPt, _
    sBlkName, dScale, dScale, dScale, dRot)
Else
    Set acBlkRef = ThisDrawing.ModelSpace.InsertBlock(dInsPt, _
    sBlkName, dScale, dScale, dScale, dRot)
End If

'--------------------------------------------------------------------------
'Make sure block is inserted and explode if required
'--------------------------------------------------------------------------
If Not acBlkRef Is Nothing Then
    If bExplode Then
        acBlkEnts = acBlkRef.Explode
        acBlkRef.Delete 'Gets rid of original copy, leaves exploded one
        If bLastObj Then
            Set InsertBlkRef = EntLast 'last modelspace entity
        End If
        Set acBlkRef = Nothing
    Else
        Set InsertBlkRef = acBlkRef
    End If
End If
    
ExitHere:
    Exit Function
ErrHandler:
    Debug.Print vbObjectError + 514, "PP_ACAD Error", _
    "Function 'InsertBlkRef' Failed"
    Err.Clear
End Function

"Everybody is ignorant, only on different subjects." — Will Rogers

RE: How to use customized toolbar item for a block insertion?

(OP)
thanks borgunit, I'm trying!

RE: How to use customized toolbar item for a block insertion?

Is there a way to insert a single specified block from with in a drawing containing multiple blocks? (other then the design center!)?

RE: How to use customized toolbar item for a block insertion?

Just insert and specify the block name. AutoCAD works with names.

"Everybody is ignorant, only on different subjects." — Will Rogers

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources