TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: JohnSnow on July 24, 2023, 09:54:18 AM

Title: Can anyone help me convert this autolisp to C#?
Post by: JohnSnow on July 24, 2023, 09:54:18 AM
I have spent quite a long time trying to convert the following code (provide by gile from another website) to C# with no luck so far.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:RotateToView (/ n ss ent elst)
  2.  (if (setq norm (trans '(0. 0. 1.) 2 0 T)
  3.        n     -1
  4.        ss     (ssget '((0 . "POINT,TEXT")))
  5.      )
  6.    (while (setq ent (ssname ss (setq n (1+ n))))
  7.      (setq elst (entget ent)
  8.        ins     (assoc 10 elst)
  9.      )
  10.      (if (= (cdr (assoc 0 elst)) "TEXT")
  11.    (entmod    (subst (cons 10 (trans (cdr ins) ent norm))
  12.               ins
  13.               (subst (cons 210 norm) (assoc 210 elst) elst)
  14.        )
  15.    )
  16.    (entmod (subst (cons 210 norm) (assoc 210 elst) elst))
  17.      )
  18.    )
  19.  )
  20.  (princ)
  21. )

edit-kdub:add code tags
Title: Re: Can anyone help me convert this autolisp to C#?
Post by: JohnSnow on July 24, 2023, 09:55:20 AM
It is to roate the text to the current view.
So I have done something like this: (Bascially set the text normal and position to suit)
But it doesn't work.

Code - C#: [Select]
  1.             Document doc = Application.DocumentManager.MdiActiveDocument;
  2.             Database db = doc.Database;
  3.             Editor ed = doc.Editor;
  4.  
  5.             using (Transaction tr = db.TransactionManager.StartTransaction())
  6.            {
  7.                 BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  8.                 BlockTableRecord modelSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  9.                 ViewTableRecord CurrentView = ed.GetCurrentView();
  10.  
  11.                 var DCS2WCS =   Matrix3d.Rotation(-CurrentView.ViewTwist, CurrentView.ViewDirection, CurrentView.Target) *
  12.                                            Matrix3d.Displacement(CurrentView.Target - Point3d.Origin) *
  13.                                            Matrix3d.PlaneToWorld(CurrentView.ViewDirection);
  14.  
  15.                 Vector3d norm = new Vector3d(0, 0, 1).TransformBy(DCS2WCS);
  16.                Matrix3d WCS2OCS = Matrix3d.WorldToPlane(norm);
  17. ....
  18.                 text.Normal = norm;
  19.                 text.Position = text.Position.TransformBy(WCS2OCS);
  20.  
  21. .....
  22.  
  23.  

edit-kdub:add code tags
Title: Re: Can anyone help me convert this autolisp to C#?
Post by: HOSNEYALAA on July 25, 2023, 12:56:23 AM


Hi
Can you attached example drawing
Title: Re: Can anyone help me convert this autolisp to C#?
Post by: JohnSnow on July 25, 2023, 05:26:44 AM
I have have any drawings in particular. It can be any drawings.

What I am struggling with is to convert the following to C#:

Code - Auto/Visual Lisp: [Select]
  1. (trans (cdr ins) ent norm)


edit-kdub : code tags added
Title: Re: Can anyone help me convert this autolisp to C#?
Post by: JohnK on July 25, 2023, 12:27:41 PM
I have have any drawings in particular. It can be any drawings.

What I am struggling with is to convert the following to C#:
(trans (cdr ins) ent norm)
I haven't looked at any of the code yet but let me just put this out there (so I can possibly look like a complete idiot).
TRANS: https://www.theswamp.org/Sources/doc/avlisp/#trans
Title: Re: Can anyone help me convert this autolisp to C#?
Post by: Jeff_M on July 25, 2023, 07:10:56 PM
It is to rotate the text to the current view.

But it doesn't work.
Why do you think this? It appears to work for me. You didn't show your whole code so I can't speculate what may be causing it to not work for you.
Title: Re: Can anyone help me convert this autolisp to C#?
Post by: It's Alive! on July 26, 2023, 06:46:24 AM
there's aWcs2Dcs here, maybe just get the inverse
 https://adndevblog.typepad.com/autocad/2012/06/setting-the-view-center-in-an-external-dwg-file-with-objectarx-or-realdwg-in-c.html

actually the sample uses inverse, so just remove that line... maybe...
Title: Re: Can anyone help me convert this autolisp to C#?
Post by: BIGAL on July 26, 2023, 09:05:28 PM
If you have an old PC in the closest, try LISP2C its 8bit software made years ago to convert lsp to C.

Yes have a copy but does not run on 64 Bit pc.