TheSwamp
Code Red => VB(A) => Topic started by: NWcivil77 on April 13, 2006, 12:13:19 AM
-
Hello,
I have the attached snippet in a block insertion routine, and one of the things I can't figure out is how to insert a block into model space from an active viewport in paperspace. Currently if you are in paperspace with an active model space viewport it will insert the block somewhere off in paperspace. Could someone steer me in a new direction with this? Thanks...
If VAR = 1 Then
Set blkObj = ThisDrawing.ModelSpace.InsertBlock(PNT, blkname, ScaleVal, ScaleVal, ScaleVal, ANG)
Else
Set blkObj = ThisDrawing.PaperSpace.InsertBlock(PNT, blkname, ScaleVal, ScaleVal, ScaleVal, ANG)
End If
-
Not enough info but I'm backing your var is lying.
Put the following in thisdrawing
'Thank Glenn R
Public Property Get CurrentSpace() As AcadBlock
If Me.GetVariable("CVPORT") = 1 Then
Set CurrentSpace = Me.PaperSpace
Else
Set CurrentSpace = Me.ModelSpace
End If
End Property
Set blkObj = ThisDrawing.CurrentSpace.InsertBlock(PNT, blkname, ScaleVal, ScaleVal, ScaleVal, ANG)
-
Thanks for the reply and please forgive my novice ability, here is the total code for my module, I am having trouble applying the code posted previously...
Option Explicit
Global layobj As AcadLayer
Global layername As String
Global layercolor As OLE_COLOR
Dim clayer As AcadLayer
Global blkname As String
Dim ANGVARNAME As String
Dim ANG As String
Dim sysvarname As String
Dim VAR As String
Dim ScaleVal As String
Dim PNT As Variant
Dim blkObj As AcadBlockReference
Public Static Property Get CurrentSpace() As AcadBlock
If Me.GetVariable("CVPORT") = 1 Then
Set CurrentSpace = Me.PaperSpace
Else
Set CurrentSpace = Me.ModelSpace
End If
End Property
Public Static Function blockin()
On Error Resume Next
Set clayer = ActiveDocument.ActiveLayer
Set layobj = ThisDrawing.Layers.Item(layername)
If Err <> 0 Then
Set layobj = ThisDrawing.Layers.Add(layername)
layobj.Color = layercolor
End If
ActiveDocument.ActiveLayer = layobj
ANGVARNAME = "SNAPANG"
ANG = ThisDrawing.GetVariable(ANGVARNAME)
sysvarname = "tilemode"
VAR = ThisDrawing.GetVariable(sysvarname)
If blks.fullscale.Value = True Then ScaleVal = 1
If blks.tenscale.Value = True Then ScaleVal = 10
If blks.twentyscale.Value = True Then ScaleVal = 20
If blks.thirtyscale.Value = True Then ScaleVal = 30
If blks.fortyscale.Value = True Then ScaleVal = 40
If blks.fiftyscale.Value = True Then ScaleVal = 50
If blks.sixtyscale.Value = True Then ScaleVal = 60
If blks.onexxscale.Value = True Then ScaleVal = 100
'Get the points from the user
PNT = ThisDrawing.Utility.GetPoint _
(, vbCrLf & "Insertion point: ")
Set blkObj = ThisDrawing.CurrentSpace.InsertBlock(PNT, blkname, ScaleVal, ScaleVal, ScaleVal, ANG)
'If VAR = 1 Then
'Set blkObj = ThisDrawing.ModelSpace.InsertBlock(PNT, blkname, ScaleVal, ScaleVal, ScaleVal, ANG)
'Else
'Set blkObj = ThisDrawing.PaperSpace.InsertBlock(PNT, blkname, ScaleVal, ScaleVal, ScaleVal, ANG)
'End If
ActiveDocument.ActiveLayer = clayer
Set layobj = Nothing
Set clayer = Nothing
Set PNT = Nothing
Set blkObj = Nothing
End Function
-
No worries.
"Me" can only be used in the thisdrawing module or forms. So if you place the function in a standard module replace the me with thisdrawing.
Public Static Property Get CurrentSpace() As AcadBlock
If ThisDrawing.GetVariable("CVPORT") = 1 Then
Set CurrentSpace = ThisDrawing.PaperSpace
Else
Set CurrentSpace = ThisDrawing.ModelSpace
End If
End Function
It looks like you are using it right.
Comment out that on error next to find out.
Set layobj = ThisDrawing.Layers.Item(layername)
If Err <> 0 Then
Set layobj = ThisDrawing.Layers.Add(layername)
layobj.Color = layercolor
End If
Not needed, replace with
Set layobj = ThisDrawing.Layers.Add(layername) (This never errors for layers whereas an existing block would)
-
Excellent!! That works perfectly. Thank you very much!!!