.net - Sorting selected elements (autocad) -
please me out here. i'm trying change order of selection (which exists out of elements: lines, polylines , arcs). elements of selection attached 1 another. code needs create new list in elements sorted ending entity other ending entity.
my code:
public sub reorder() dim document document = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument dim ed editor = document.editor dim db database = document.database dim fillist typedvalue() = new typedvalue(0) {new typedvalue(cint(dxfcode.start), "lwpolyline,arc,line")} dim filter new selectionfilter(fillist) dim opts new promptselectionoptions() try opts.messageforadding = ("select items: ") dim res promptselectionresult = ed.getselection(opts, filter) if res.status <> promptstatus.ok exit sub end if dim selset selectionset = res.value dim idarray objectid() = selset.getobjectids() using document.lockdocument using trans transaction = db.transactionmanager.starttransaction() dim btr blocktablerecord = trycast(trans.getobject(db.currentspaceid, openmode.forwrite), blocktablerecord) dim lstent new list(of entity) each id objectid in idarray dim ent1 entity = directcast(trans.getobject(id, openmode.forread), entity) lstent.add(ent1) next dim tolerance_xy double = 0.01 dim lstelementensorted new list(of curve) dim blnreverse boolean = false lstelementensorted.add(lstent(0)) p integer = 0 lstent.count - 1 dim element1 curve = lstent(p) q integer = 0 lstent.count - 1 dim element2 curve = lstent(q) if not element1 element2 dim deltax double dim deltay double deltax = math.abs(element1.endpoint.x - element2.startpoint.x) deltay = math.abs(element1.endpoint.y - element2.startpoint.y) if deltax < tolerance_xy andalso deltay < tolerance_xy if not lstelementensorted.contains(element2) if blnreverse lstelementensorted.insert(0, element2) else lstelementensorted.add(element2) end if end if continue end if deltax = math.abs(element1.endpoint.x - element2.endpoint.x) deltay = math.abs(element1.endpoint.y - element2.endpoint.y) if deltax < tolerance_xy andalso deltay < tolerance_xy if not lstelementensorted.contains(element2) blnreverse = iif(blnreverse = true, false, true) if blnreverse lstelementensorted.insert(0, element2) else lstelementensorted.add(element2) end if end if continue end if deltax = math.abs(element1.startpoint.x - element2.endpoint.x) deltay = math.abs(element1.startpoint.y - element2.endpoint.y) if deltax < tolerance_xy andalso deltay < tolerance_xy if not lstelementensorted.contains(element2) if blnreverse lstelementensorted.add(element2) else lstelementensorted.insert(0, element2) end if end if continue end if deltax = math.abs(element1.startpoint.x - element2.startpoint.x) deltay = math.abs(element1.startpoint.y - element2.startpoint.y) if deltax < tolerance_xy andalso deltay < tolerance_xy if not lstelementensorted.contains(element2) blnreverse = iif(blnreverse = true, false, true) if blnreverse lstelementensorted.add(element2) else lstelementensorted.insert(0, element2) end if end if continue end if end if next next r integer = 0 lstelementensorted.count - 1 ed.writemessage(lstelementensorted.item(r).gettype.name.tostring & " - ") next trans.commit() end using end using catch ex system.exception ed.writemessage(ex.message) end try end sub
i can't figure out how should add elements list in correct order. in advance!
Comments
Post a Comment