public static string PlotSubReddit(EntityData dimstyle, string pickedSubReddit) { string result = "OK"; try { DrawEntity.DrawBox(dimstyle.origin, dimstyle.cornerBase, "REDDIT.BORDER", 20); RedditSharp.Reddit reddit = new RedditSharp.Reddit(); var subreddit = reddit.GetSubreddit(pickedSubReddit); if (subreddit != null) { Tuple <double, double> widthHeight; int i = -1; double yTextLocation = dimstyle.origin.Y; double mtextActualHeight = 0; DrawEntity.DrawDim(dimstyle.origin, new Point3d(dimstyle.cornerBase.X, dimstyle.origin.Y, 0), "/r/" + pickedSubReddit, "REDDIT.HEADINGS", dimstyle.headingTxtSize, 1.025); foreach (var post in subreddit.Hot.Take(20)) { string postId = GeneratePostId(PostMarker.postmarker); yTextLocation -= (mtextActualHeight - (dimstyle.yLength * .025)); //adds 5% height padding Point2d headingLocation = new Point2d(dimstyle.origin.X, yTextLocation); widthHeight = DrawEntity.DrawText(headingLocation, dimstyle.headingTxtSize, dimstyle.textWidth, post.Title, "REDDIT.HEADINGS", 7); mtextActualHeight = widthHeight.Item2; Point2d subHeadingLocation = new Point2d(dimstyle.origin.X, yTextLocation - mtextActualHeight); string subHeading = string.Format("By:{0} | No. Of Comments: {1} | Submitted: {2} | NSFW: {3}", post.Author.ToString(), post.CommentCount.ToString(), post.Created.ToString(), post.NSFW ? "YES":"NO"); widthHeight = DrawEntity.DrawText(subHeadingLocation, dimstyle.subHeadingTxtSize, dimstyle.textWidth, subHeading, "REDDIT.SUBHEADINGS", 251); Point2d postIdLocation = new Point2d((dimstyle.origin.X + widthHeight.Item1) + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.001), yTextLocation - mtextActualHeight); string postIdFormat = string.Format("[REDDITCAD POST ID: {0} ]", postId); DrawEntity.DrawText(postIdLocation, dimstyle.subHeadingTxtSize, dimstyle.textWidth, postIdFormat, "REDDIT.POSTID", 10); PostIds.AddPost(postId, post); i--; } } } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); result = "FAILED"; } return(result); }
public void GetPost() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptStringOptions prmptStrOpt = new PromptStringOptions("\n\n Type RedditCAD Post ID : "); PromptResult prmpRes = ed.GetString(prmptStrOpt); string postId = prmpRes.StringResult.ToUpper(); if (PostIds.Contains(postId)) { EntityData dimStyles = new EntityData(); PromptPointOptions prmptPtOptions = new PromptPointOptions("\n\nPick insertion point...."); PromptPointResult result = ed.GetPoint(prmptPtOptions); PromptCornerOptions prmptCnrOptions = new PromptCornerOptions("\n\n Click on bottom corner..", result.Value); PromptPointResult prmptCnrResult; prmptCnrResult = ed.GetCorner(prmptCnrOptions); RedditCAD.FormatRedditDim(dimStyles, result.Value, prmptCnrResult.Value); RedditCAD.PlotPost(dimStyles, postId); } else { ed.WriteMessage("\n\n Invalid AutoCAD.Reddit Post Id.."); } }
/// <summary> /// Plots reddit post based on Post Id /// </summary> /// <param name="dimstyle">object containing dim scales based on the bounding box drawn by user</param> /// <param name="id">Reddit Post ID</param> /// <returns></returns> public static string PlotPost(EntityData dimstyle, string id) { string result = "OK"; try { RedditSharp.Things.Post post = (RedditSharp.Things.Post)PostIds.GetPost(id); if (IsLinkedImg(post.Url.AbsoluteUri)) { //Will insert imageif link is a direct link to the image string filename = GetImage(post.Url.AbsoluteUri); DrawEntity.DrawImg(dimstyle.origin, filename, "REDDIT.IMGS", dimstyle.yLength * .05, dimstyle.yLength * .05); } //if it's only a link to imgur page... List <string> imgurLinks = GetImgurImgs(post.Url.AbsoluteUri); for (int i = 0; i < imgurLinks.Count; i++) { Point3d imgLocation = new Point3d(dimstyle.origin.X + (i * (dimstyle.cornerBase.X - dimstyle.origin.X)), dimstyle.origin.Y, 0); double heightNWith = dimstyle.yLength * 0.025; //Basing height and with on the height of the border drawn by user. if width & height are seperated then img will be distorted string image = GetImage(imgurLinks[i]); DrawEntity.DrawImg(imgLocation, image, "REDDIT.IMGS", heightNWith, heightNWith); } RedditSharp.Reddit reddit = new RedditSharp.Reddit(); if (post != null) { //Post generated looks like this with indentation int i = -1; //Multiplier to help to align text in the Y axis. double yTextLocation = dimstyle.origin.Y; double mtextActualHeight = (dimstyle.yLength * .0025); Point2d subHeadingLocation = new Point2d(dimstyle.origin.X, dimstyle.origin.Y); foreach (var comment in post.Comments.Take(50)) { Tuple <double, double> widthHeight; // A*C*T*U*A*L width & height of the mtext created yTextLocation -= (mtextActualHeight - (dimstyle.yLength * .0025)); //adds height padding Point2d commentLocation = new Point2d(dimstyle.origin.X, yTextLocation); widthHeight = DrawEntity.DrawText(commentLocation, dimstyle.commentsSize, dimstyle.textWidth, comment.Body, "REDDIT.COMMENTS", 7); mtextActualHeight = widthHeight.Item2; subHeadingLocation = new Point2d(dimstyle.origin.X, yTextLocation - mtextActualHeight); string subHeading = string.Format("By:{0} | Upvotes: {1} | Submitted: {2}", comment.Author, comment.Upvotes, post.Created.ToString()); DrawEntity.DrawText(subHeadingLocation, dimstyle.subCommentsSize, dimstyle.textWidth, subHeading, "REDDIT.COMMENTS.SUBHEADINGS", 251); i--; foreach (var subcomment in comment.Comments.Take(20)) { yTextLocation -= (mtextActualHeight - (dimstyle.yLength * .0025)); //adds height padding commentLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.025), yTextLocation); widthHeight = DrawEntity.DrawText(commentLocation, (dimstyle.commentsSize * 0.75), dimstyle.textWidth, subcomment.Body, "REDDIT.COMMENTS", 7); mtextActualHeight = widthHeight.Item2; subHeadingLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.025), yTextLocation - mtextActualHeight); subHeading = string.Format("By:{0} | Upvotes: {1} | Submitted: {2}", subcomment.Author, subcomment.Upvotes, subcomment.Created.ToString()); DrawEntity.DrawText(subHeadingLocation, (dimstyle.subCommentsSize * 0.75), dimstyle.textWidth, subHeading, "REDDIT.COMMENTS.SUBHEADINGS", 251); i--; foreach (var subsubcomment in subcomment.Comments.Take(15)) { yTextLocation -= (mtextActualHeight - (dimstyle.yLength * .0025)); //adds height padding commentLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.05), yTextLocation); widthHeight = DrawEntity.DrawText(commentLocation, (dimstyle.commentsSize * 0.5), dimstyle.textWidth, subsubcomment.Body, "REDDIT.COMMENTS", 7); mtextActualHeight = widthHeight.Item2; subHeadingLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.05), yTextLocation - mtextActualHeight); subHeading = string.Format("By:{0} | Upvotes: {1} | Submitted: {2}", subsubcomment.Author, subsubcomment.Upvotes, subsubcomment.Created.ToString()); DrawEntity.DrawText(subHeadingLocation, (dimstyle.subCommentsSize * 0.5), dimstyle.textWidth, subHeading, "REDDIT.COMMENTS.SUBHEADINGS", 251); i--; foreach (var subsubsubcomment in subsubcomment.Comments.Take(10)) { yTextLocation -= (mtextActualHeight - (dimstyle.yLength * .0025)); //adds height padding commentLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.075), yTextLocation); widthHeight = DrawEntity.DrawText(commentLocation, (dimstyle.commentsSize * .25), dimstyle.textWidth, subsubsubcomment.Body, "REDDIT.COMMENTS", 7); mtextActualHeight = widthHeight.Item2; subHeadingLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.075), yTextLocation - mtextActualHeight); subHeading = string.Format("By:{0} | Upvotes: {1} | Submitted: {2}", subsubsubcomment.Author, subsubsubcomment.Upvotes, subsubsubcomment.Created.ToString()); DrawEntity.DrawText(subHeadingLocation, (dimstyle.subCommentsSize * 0.25), dimstyle.textWidth, subHeading, "REDDIT.COMMENTS.SUBHEADINGS", 251); i--; } } } } Point3d endPt = new Point3d(dimstyle.cornerBase.X - ((dimstyle.cornerBase.X - dimstyle.origin.X) / 2), subHeadingLocation.Y - (subHeadingLocation.Y * 0.0025), 0); DrawEntity.DrawBox(dimstyle.origin, endPt, "REDDIT.BORDER", 20); DrawEntity.DrawDim(dimstyle.origin, new Point3d(endPt.X, dimstyle.origin.Y, 0), "POST ID : " + id, "REDDIT.COMMENTS", dimstyle.subHeadingTxtSize, 1.005); } } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); result = "FAILED"; } return(result); }