Routines in CBL involving polyline linesets
select case CdiGetProgMode()
case CDI_2D_MODE
i_ret%=CdiMenuEntry(IDM_DRAW_LINE_LINE_SET, term%, menu_hit%)
case CDI_3D_MODE
i_ret%=CdiMenuEntry(IDM_DRAW3_LINE, term%, menu_hit%)
end select
Selecting a line segment and getting it's midpoint:
sub GetMidPoint()
dim object1 as CDI_OSL_OBJECT
dim line_buffer as CDI_LINESET_BUFFER
dim vertex_id1 as integer
dim vertex_id2 as integer
dim null_ptr as long
dim pnt0 as CDI_DDD_POINT
dim pnt1 as CDI_DDD_POINT
dim pnt2 as CDI_DDD_POINT
dim center as CDI_DDD_POINT
dim snapmode as integer
dim l_osl as long
dim op as integer
l_osl&=CdiCreateLocalOsl(CDI_OBJECT_COLOR, 0&, CDI_REDRAW_OSL)
snapmode%=CdiGetSnapMode()
i_ret=CdiSetSnapMode(CDI_NOSNAP)
i_ret=CdiSelectbyPoint(l_osl&,"Select line segment for center point",CDI_OBJECT_SELECTION,CDI_FALSE,CDI_TRUE,pnt0(0),CDI_SEL2D_LINESETS)
if i_ret=CDI_ABORT or i_ret=CDI_ERROR then
i_ret=CdiSetSnapMode(snapmode%)
i_ret=CdiFreeLocalOsl(l_osl&)
exit sub
end if
i_ret=CdiOslItem(l_osl, 0, object1)
i_ret=CdiSelectLineSegment(object1.sid, pnt0, vertex_id1, vertex_id2)
i_ret=CdiObjInfo(object1.sid, line_buffer)
i_ret=CdiObjInfoxy(pnt1, op, vertex_id1-1, line_buffer)
i_ret=CdiObjInfoxy(pnt2, op, vertex_id2-1, line_buffer)
call CdiLineCenter(pnt1, pnt2, center)
call CdiCoordInput(center, CDI_ABS_UNITS)
i_ret=CdiSetSnapMode(snapmode)
i_ret=CdiFreeLocalOsl(l_osl)
end sub
Calculating the length of a polyline lineset:
sub LineLength()
Dim line_buffer As CDI_LINESET_BUFFER
Dim pnt1 as CDI_DDD_POINT
Dim object1 as CDI_OSL_OBJECT
i_ret%=CdiSelectbyPoint(0&, "Select line to find total length", CDI_OBJECT_SELECTION, CDI_FALSE, CDI_TRUE, pnt0, CDI_SEL2D_ALL)
i_ret%=CdiOslItem(0&, 0, object1.sid)
i_ret%=CdiObjInfo(object1.sid, line_buffer)
length&=0
i_ret%=CdiObjInfoxy(pnt1, op%, 0, line_buffer)
for vertex%=1 to line_buffer.number_of_elements
i_ret%=CdiObjInfoxy(pnt2, op%, vertex%, line_buffer)
distance&=0
call CdiWorldDist(pnt1, pnt2, distance&)
pnt1=pnt2
length&=length&+distance&
next vertex%
'convert from database units to current units
dim dist as string * 30
call CdiDbutoString(length&, dist)
msg$="length = "+dist
msgbox msg$,0
end sub
Calculating the area of a polyline lineset using CdiAreaCalc:
sub GetArea()
Dim line_buffer As CDI_LINESET_BUFFER
Dim pnt1 as CDI_DDD_POINT
Dim object1 as CDI_OSL_OBJECT
i_ret%=CdiSelectbyPoint(0&, "Select line to find area", CDI_OBJECT_SELECTION, CDI_FALSE, CDI_TRUE, pnt0, CDI_SEL2D_ALL)
i_ret%=CdiOslItem(0&, 0, object1.sid)
i_ret%=CdiObjInfo(object1.sid, line_buffer)
ReDim xp(lvertex) As Long
ReDim yp(lvertex) As Long
For vertex%=0 To line_buffer.number_of_elements
i_ret%=CdiObjInfoxy(pnt1, op%, vertex%, line_buffer)
xp(vertex%)=pnt1.x
yp(vertex%)=pnt1.y
Next vertex%
area#=0#
Call CdiArea(xp(0), yp(0), line_buffer.number_of_elements, area#)
'convert from database units to current units
'factor for square feet
carea=144
msg$="area = "+area#/carea/CdiPntsPerUnit^2
msgbox msg$,0
end sub
Adding a vertex to the end of a polyline lineset
sub AddVertex()
Dim line_buffer As CDI_LINESET_BUFFER
Dim pnt0 as CDI_DDD_POINT
Dim pnt1 as CDI_DDD_POINT
Dim object1 as CDI_OSL_OBJECT
i_ret%=CdiSelectbyPoint(0&, "Select line to add vertex", CDI_OBJECT_SELECTION, CDI_FALSE, CDI_TRUE, pnt0, CDI_SEL2D_ALL)
i_ret%=CdiOslItem(0&, 0, object1.sid)
i_ret%=CdiObjInfo(object1.sid, line_buffer)
i_ret%=CdiGetPoint("Select new vertex point",pnt1)
i_ret%=CdiVertexAdd(object1.sid ,line_buffer.number_of_elements, pnt1, op%, CDI_ABS_UNITS, CDI_OBJECT_COLOR, new_segid&)
end sub
More CBL Sample Code - Selection Sets