Friday, April 10, 2009

Shortest path find

Hi Friends,
To start with our AutoCAD programming. we are posting a tool to find out the shortest path between two points.

(Defun GetShortestPath (pt1 pt2 Toponame)
(setq returnset (ssadd))
;;(if (tpm_acexist Toponame) (tpm_acload Toponame))
(setq topo_id (tpm_acopen Toponame nil))
(setq trace_id (tpm_tracealloc topo_id))
(setq node1_id (tpm_elemfind topo_id 1 pt1))
(setq node2_id (tpm_elemfind topo_id 1 pt2))
(setq TS (tpm_traceshort trace_id node1_id node2_id))
(if TS
(progn
(setq loop T)
(setq ctr 0)
(setq tracelen (tpm_traceqty trace_id 2))
(while (< ctr tracelen)
(setq elem_id (tpm_traceelemid trace_id 2 ctr))
(setq eleminfo (tpm_elemget topo_id elem_id))
(if eleminfo
(progn
(setq ent (cdr (assoc -2 eleminfo)))
(if ent (setq returnset (ssadd ent returnset)))
)
)
(setq ctr (1+ ctr))
)
)
)
(tpm_tracefree trace_id)
(tpm_acclose topo_id)
;;(tpm_acunload Toponame)
(princ)
returnset
)

Please post ur comments on this.

No comments:

Post a Comment