wannabe Posted October 23, 2008 Posted October 23, 2008 Please could someone tell me how I should set about producing a VBA macro that will, operated by a form, allow me to select a polyline,line or 3d polyline; then select a block; and finally select the spacing between the blocks to be inserted on the selected line,poly,3dpoly etc. One Issue I may have is that I will need the spacing to be X coordinate only, and I will need to ignore the Z coordinates. The drawing is a plan view which, like I said above, will have some contours that I need to totally ignore, hence the point above. Ideally I just want to be pushed and nudged in the right direction and will try and work out the code as much as possible myself (judging by other threads I will probably need a lot more help from you experts ). Thanks in advance. Quote
borgunit Posted October 23, 2008 Posted October 23, 2008 Have you started any part of the macro yet? And could we see it? Quote
wannabe Posted October 23, 2008 Author Posted October 23, 2008 No I havent started now it seems the measure command can do all this anyway as long as I make a copy of a 3d poly and remove its Z coords. Quote
BIGAL Posted October 24, 2008 Posted October 24, 2008 This bit of code places a block "holden" along a poly line based on the spacing between the vertice points just simply divided into intervals you could modify to work on a fix spacing distance instead. A good start point. Also search here for batterticks For those interested its used to check if a car bottoms out in a vehicle crossing. Sub draw_vehicle() Dim CAR As String Dim arcobj As AcadArc Dim oPoly As AcadEntity Dim blkobj As AcadEntity Dim retVal As Variant Dim snapPt As Variant Dim oCoords As Variant Dim blpnt1() As Variant ReDim blpnt1(100) Dim blpnt2() As Variant ReDim blpnt2(100) Dim vertPt(0 To 2) As Double Dim Pt1(0 To 2) As Double Dim Pt2(0 To 2) As Double Dim newPt(0 To 2) As Double Dim iCnt, w, x, y, z As Integer Dim cRad, interval, blkangle As Double Dim circObj As AcadCircle Dim lineObj As AcadLine On Error GoTo Something_Wrong For Each Item In ThisDrawing.Blocks If Item.Name = "holden" Then GoTo continue_on Next Item ' exits out of program GoTo Exit_out continue_on: w = 1 ThisDrawing.Utility.GetEntity oPoly, snapPt, vbCr & "Select polyline :" If oPoly.ObjectName = "AcDbPolyline" Then oCoords = oPoly.Coordinates Else: MsgBox "This object is not a polyline!" Exit Sub End If interval = CDbl(InputBox("Enter interval:", , 1#)) If interval < 1 Then interval = 1 End If For iCnt = 0 To UBound(oCoords) - 2 Step 2 Pt1(0) = oCoords(iCnt): Pt1(1) = oCoords(iCnt + 1): Pt1(2) = 0# newPt(0) = Pt1(0) newPt(1) = Pt1(1) newPt(2) = 0# iCnt = iCnt + 2 Pt2(0) = oCoords(iCnt): Pt2(1) = oCoords(iCnt + 1): Pt2(2) = 0# x = (Pt1(0) - Pt2(0)) / interval y = (Pt1(1) - Pt2(1)) / interval 'reset back 2 values iCnt = iCnt - 2 cRad = 2.8 startang = 4.712 endang = 1.57 CAR = "HOLDEN" For z = 1 To interval vertPt(0) = newPt(0) - x vertPt(1) = newPt(1) - y vertPt(2) = 0# 'blpnt1(w) = vertPt Set arcobj = ThisDrawing.ModelSpace.AddArc(vertPt, cRad, endang, startang) retval2 = arcobj.IntersectWith(oPoly, acExtendOtherEntity) arcobj.Delete Set arcobj = Nothing blkangle = ThisDrawing.Utility.AngleFromXAxis(retval2, vertPt) Set blkobj = ThisDrawing.ModelSpace.InsertBlock(vertPt, CAR, 1#, 1#, 1#, blkangle) Set blkobj = Nothing w = w + 1 newPt(0) = newPt(0) - x newPt(1) = newPt(1) - y Next z Next iCnt Something_Wrong: MsgBox Err.Description Exit_out: End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.