View Full Version : VBA question
dwoodmansee
13th Jan 2005, 05:05 pm
I created some vb code to break a line and insert a block. This works until the break line is a the same point as the block. I get a message cann't break a block. Can I force the vb code to do the break first the the insert? I have tried seperating the two tasks in different subs and different modules, still get the same result. It appears the drawing is not updated until all the code is exicuted.
hendie
13th Jan 2005, 05:16 pm
would really need to see the code.. but at a guess ~ are you filtering to get the line ?
dwoodmansee
13th Jan 2005, 05:31 pm
I am using the a selection set to determine if there is a line then just calculating the break points. Here is the code.
Sub Break_Line_cb1h()
Dim ipt As Variant
Dim pt1(0 To 2) As Double
Dim pt2(0 To 2) As Double
Dim ssetObj As AcadSelectionSet
Dim Objtype As String
Dim width As Double
Dim x1 As String
Dim y1 As String
Dim x2 As String
Dim y2 As String
Dim Name As String
Dim File As String
width = 0.2
Name = "cb1h"
File = "C:\Program Files\ACAD2000\My_Support\MY_Symbols\" & Name & ".dwg"
ipt = ThisDrawing.Utility.GetPoint(, "Insertion point: ")
Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
On Error Resume Next
ssetObj.SelectAtPoint ipt
On Error Resume Next
Objtype = ssetObj.Item(0).ObjectName
If Objtype = "AcDbLine" Then
pt1(0) = ipt(0) - width
pt1(1) = ipt(1)
x1 = ThisDrawing.Utility.RealToString(pt1(0), acDecimal, 4)
y1 = ThisDrawing.Utility.RealToString(pt1(1), acDecimal, 4)
pt2(0) = ipt(0) + width
pt2(1) = ipt(1)
x2 = ThisDrawing.Utility.RealToString(pt2(0), acDecimal, 4)
y2 = ThisDrawing.Utility.RealToString(pt2(1), acDecimal, 4)
ThisDrawing.SendCommand "_break"
ThisDrawing.SendCommand " " & x1 & "," & y1
ThisDrawing.SendCommand " " & x2 & "," & y2 & " "
End If
ssetObj.Delete
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(ipt, File, 1#, 1#, 1#, 0)
pt1(0) = ipt(0) - 0.2
pt1(1) = ipt(1)
x1 = ThisDrawing.Utility.RealToString(pt1(0), acDecimal, 4)
y1 = ThisDrawing.Utility.RealToString(pt1(1), acDecimal, 4)
ThisDrawing.SendCommand "_attedit"
ThisDrawing.SendCommand " " & x1 & "," & y1 & " "
End Sub
hendie
13th Jan 2005, 05:41 pm
Don't use Sendcommand.
If you're going to "break" the line. First, get the line and the point you want to break it at.
Then get the startpoint and endpoint values of the line.
Keep the startpoint of the line but substitute the breakpoint for the line Endpoint. Update the object.
Now add a new line.
Make the Startpoint the breakpoint and make the Endpoint the Endpoint of the orignal line.
If you're going to break the line with a gap, then you will need to calculate the new points relative to the breakpoint.
You are correct in getting the point as a variant but once you have the data it's easier to use it like
(ReTurnPnt is the variant data)
EPnt(0) = (ReTurnPnt(0) + R): EPnt(1) = ReTurnPnt(1): EPnt(2) = 0#
StartPnt(0) = (ReTurnPnt(0) + Rs): StartPnt(1) = ReTurnPnt(1): StartPnt(2) = 0#
Set CLine = ThisDrawing.ModelSpace.AddLine(StartPnt, EPnt)
Simple No ? 8)
dwoodmansee
13th Jan 2005, 05:47 pm
If I get what your saying, delete the original line and add two new lines to create the gap?
hendie
13th Jan 2005, 05:57 pm
In essence yes, but don't delete the original line ~ just replace the Endpoint with a new value and update the object ~ it's less work !
Barry Clark
14th Jan 2005, 04:09 am
Don't mean to hi-jack, but I honestly have never come across the problems that I have always heard people have with sendcommand. I avoided it for quite awhile just because of all of the horrorstories about routines going pear-shaped. I decided one day to be daring and use it to save me quite a bit of programming and I have been using it occasionally ever since. I am not saying that everyone is wrong by any means, but I just have never had an issue.
hendie
14th Jan 2005, 09:18 am
Neither have I but I've used it only once or twice on very rare occasions.
But it is causing a problem with the routine above as the use of Sendcommand and feeding it points is causing Acad to select the incorrect object i.e. the block instead of the line.
Using filters to select the objects and then updating the object data means that you are sure you're updating exactly what you are trying to update.
and once you start building up your code library, it's just as easy to copy and paste and change a few details as it is to write a Sendcommand statement
dwoodmansee
14th Jan 2005, 12:45 pm
works great thanks
Barry Clark
14th Jan 2005, 02:19 pm
copy and paste and change a few details as it is to write a Sendcommand statementThat is what I do for the most part.
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.