Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get viewport Type

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
anhtrung
804 Views, 8 Replies

Get viewport Type

i want get viewport type in Layout. so can everybody help me please? Thks

8 REPLIES 8
Message 2 of 9
Jeff_M
in reply to: anhtrung

This is found in the Viewport's Xdata:

    public static class ViewportExtensions
    {
        /// <summary>
        /// Returns the Viewort type:
        /// 0 = undefined,
        /// 1 = Plan,
        /// 2 = Profile,
        /// 3 = Section
        /// </summary>
        /// <param name="vp"></param>
        /// <returns></returns>
        public static short GetViewportType(this Viewport vp)
        {
            short vptype = 0;
            var xArray = vp.XData.AsArray();
            int i = -1;
            foreach (TypedValue tv in xArray)
            {
                i++;
                try
                {
                    if ((string)tv.Value == "AeccPlanProd50ViewportType")
                    {
                        vptype = (short)xArray[i + 1].Value;
                        break;
                    }
                }
                catch { }
            }
            return vptype;
        }
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 9
JanardFugro
in reply to: anhtrung

Hi, Is there some cords to get these viewport types by autolisp ?  

        /// 0 = undefined,
        /// 1 = Plan,
        /// 2 = Profile,
        /// 3 = Section
Message 4 of 9
JanardFugro
in reply to: anhtrung

Sorry, I mean Is there some codes to get these viewport types by autolisp ? 

Message 5 of 9
BlackBox_
in reply to: JanardFugro


@JanardFugro wrote:

Sorry, I mean Is there some codes to get these viewport types by autolisp ? 


(defun _GetViewportType	(vpEname / vpType)
  (cond
    ((=	1
	(setq vpType
	       (cdr
		 (cadr
		   (cadr (assoc	-3
				(entget vpEname '("AeccPlanProd50ViewportType"))
			 )
		   )
		 )
	       )
	)
     )
     "Plan"
    )
    ((= 2 vpType) "Profile")
    ((= 3 vpType) "Section")
    (T "Undefined")
  )
)


"How we think determines what we do, and what we do determines what we get."

Message 6 of 9
JanardFugro
in reply to: BlackBox_

Hi Blckbox,

 

Thank you for the fast reply. 

I am not that good in autolisp programing, can you please explain with a simple example, how can I call this function in any other autolisp command. I tried by selecting a viewport but not worked.

Message 7 of 9
BlackBox_
in reply to: JanardFugro

No problem: 

 

(defun c:ListViewportType (/ ss)
  (if (setq ss (ssget ":S:E" '((0 . "VIEWPORT"))))
    (prompt
      (strcat
	"\nViewport Type is: "
	(_GetViewportType (ssname ss 0))
	" \n"
      )
    )
  )
  (princ)
)


"How we think determines what we do, and what we do determines what we get."

Message 8 of 9
JanardFugro
in reply to: BlackBox_

Thank you very much BlackBox. It worked well, brilliant work.
Message 9 of 9
BlackBox_
in reply to: JanardFugro


@JanardFugro wrote:
Thank you very much BlackBox. It worked well, brilliant work.

 

You're welcome, @JanardFugro :beer:

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report